I have Active Model Serializer setup and I have the create action to render show on successful creation of the record. If I go directly to a record by URL (/xyz/1) then it renders just fine using AMS. However when using the render method I get the following error:
ctionView::MissingTemplate at /contracts.json
==============================================
> Missing template v1/contracts/show, v1/base/show, base/show, application/show with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby]}. Searched in:
I have a feeling if I create a show.erb.json file then the message will go away but then Active Model serializer will not be used.
Here is the line with that is causing the error:
render :show, status: :created, location: get_resource
If the get_resource method is needed please let me know.
Related
I have a view with the following format:
show_map.html+phone.slim
I am testing my controller, expecting my test to render that template , does anyone know the proper syntax for rendering a view with variant ?
This is what I am trying:
describe "show_map action" do
it "renders show map view" do
get :show_map, {:id=>#job.id,:format=>:html,:variants=>:phone}
expect(response).to render_template('show_map')
end
also tried
get :show_map, {:id=>#job.id,:format=>'html.phone'}
Either way, I get a missing template error:
JobsController show_map action renders show map view
Failure/Error: get :show_map, {:id=>#job.id,:format=>:html,:variants=>:phone}
ActionView::MissingTemplate:
Missing template jobs/show_map, application/show_map with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :slim]}
Anyone know how to do this?
I'm a newbie to Rails and beginning my crud application. I've created the form perfectly fine but when I click the submit button this error appears, could someone please explain the error and how I would go about resolving this error
Missing template posts/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/Users/shannon/beginner/app/views"
My controller:
class PostsController < ApplicationController
def new
end
def create
render plain: params[:posts].inspect
end
May be you are using Rails version prior 4.1, render plain is added in Rails 4.1. So Rails is ignoring plain option and looking for template posts/create.
in Rails 4.1 you can do:
render plain: params[:posts].inspect
in Rails 4.0 you need to do:
render text: params[:posts].inspect
I'm attempting to use a jbuilder template.
Given the controller,
class Api::ReviewsController < ApplicationController
before_filter :authenticate_user!
respond_to :json
def create
#review_request = ReviewRequest.new(review_request_params.merge(user_id: current_user.id))
if #review_request.save
render 'review_requests/review'
else
head :forbidden
end
end
end
and I have the jbuilder template stored at app/views/review_requests/review.json.jbuilder
json.review_request do
json.(#review_request, :title,)
end
I'm getting a template note found error.
ActionView::MissingTemplate (Missing template review_requests/review with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/jd/Dropbox/application-code/antipattern/app/views"
* "/Users/jd/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/devise-3.4.1/app/views"
* "/Users/jd/Dropbox/application-code/antipattern"
* "/"
):
app/controllers/api/reviews_controller.rb:8:in `create'
Any thoughts on either where the correct place to store this template is or why rails isn't finding the template i'm using (if the storage location happens to be ok)?
jbuilder needs a json type web request, an html request to a rails server will cause the jbuilder template to not be rendered.
i've a problem
i'm trying to make an action method like this
def webm
#url = Video.find(params[:id]).avatar.url(:webm_sd)
end
and i just want to return the #url value without using view .. it will return string url i need it to be rendered where ever the method get called
it gives me error
Missing template api/v1/videos/webm, application/webm with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
and even if i add some views in videos folder it still gives me the same error!
what should i do?
You can use proper renderer
render json: #url
or to render just string
render text: #url
In my Rails app, I have in the Application controller
respond_to :json
A controller that inherits Application controller responds with json like so in the action...
# Some code
if mission_updated.eql? true
render :json => {}
else
render :json => {}
end
However, whenever I run a rspec test in reference to the above action
it "should return appropriate response" do
post :update_unlocked_missions
parsed_body = JSON.parse(response.body)
parsed_body.should == {}
end
I'm returned with the following rspec error
ActionView::MissingTemplate:
Missing template api/v1/missions/update_unlocked_missions, api/v1/base/update_unlocked_missions with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :rabl, :haml]}. Searched in:
* "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007f9ea2903b00>"
My question is why is it going to the view when it should respond with json and how do I fix this?
Try testing with an action that's just render json: {}. If that works, the problem is probably something in mission_updated.