Search code examples
ruby-on-railsjbuilder

jbuilder view renders with layout


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

  1. add layout:false to the render call with the json view
  2. call render partial instead a regular render.

I'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 ?


Solution

  • 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.