Last Updated: February 25, 2016
· jalada
Profile picture may 2012

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.html do
    render layout: "embed"

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!

Say Thanks
Awesome Job

Ef9be4f0 bf41 11e7 8c55 1b63032076c4
Web Engineer
Remote or Fulton, Maryland
Full Time