Eugene
Eugene

Reputation: 546

When rendering js.erb file, it renders layout with the javascript, is it a bug?

A workaround that I found was to explicitly state in controller

render :action => :some_action, :layout => false

otherwise JavaScript fails to work

Anyone found this problem or maybe something is wrong with my configuration...

Upvotes: 1

Views: 423

Answers (2)

Eugene
Eugene

Reputation: 546

Real solution: I had rhtml for layouts and rails was defaulting all templates to that layout. Once I renamed all rhtml to html.erb, it fixed the problem. Here is the article about this in detail: http://yehudakatz.com/2009/06/18/and-the-pending-tests-they-shall-pass/

Upvotes: -1

shingara
shingara

Reputation: 46914

it's a normal behaviour. How he know that you don't want render this layout ?

You can avoid the layout to all of your js format in add in your ApplicationController

Class ApplicationController

  layout :no_in_js_format

  def no_in_js_format
    if request.format == :js
      return nil
    else
      return 'application
    end
  end
end

Upvotes: 2

Related Questions