Reputation: 21015
I have a controller that sometimes renders html and sometimes json.
For json I use jbuilder views.
There is a default html layout, that for some unknown reason start to get rendered also for the json view.
I found 2 options that fixes the issue
layout:false
to the render call with the json viewI'm just wondering(cause it didn't rendered the layout a few days ago) Is there a way to tell rails to render the layout only for html request formats ?
Upvotes: 1
Views: 745
Reputation: 21015
Apparently if you layout file name does not have a .html it'll be used for all request types.. my layout file was x.erb changing it to x.html.erb solves this issue.
Upvotes: 8
Reputation: 3339
Check this out :
respond_to do |format|
format.html { render 'something.html.erb'}
format.json { render json: @next_level.to_json ,layout: false}
end
Upvotes: 0