Rails: Why are my JS views rendering with my HTML layout wrapped around them?
In my Rails 3 controller I had this simple piece of code:
respond_to do |format|
format.js
format.html do
render layout: "embed"
end
end
I couldn't understand why when I called the action with format set to js my Javascript view would be rendered with my standard HTML application layout wrapped around it.
Turns out that at some point something or someone had given my application layout the filename application.haml
instead of application.html.haml
. This made it apply to all formats instead of just HTML.
Once I renamed the layout, the problem went away!
Written by David Somers
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#