Duplicate compiled script using coffee_script helper #4

wants to merge 1 commit into


None yet
2 participants

astupka commented Nov 17, 2010

This fix will avoid duplicate rendering of coffee script within the block passed to the the coffee_script helper. This occurs in ruby 1.8.7 and 1.9.2

To reproduce in rails 3:

  1. rails new test_bistro

  2. rails g controller Foo index

  3. add bistro_car to Gemfile

  4. Remove activerecord, actionmailer from config/application.rb

    require "action_controller/railtie"
    require "active_resource/railtie"
    require "rails/test_unit/railtie"

  5. Comment out the action_mailer setting in development.rb

  6. Edit index.html.erb to contain
    <% coffee_script do%>
    a = new Bar
    <% end %>

  7. The compiled coffee script will be duplicated in the HTTP response from http:/localhost:3000/index

astupka commented Nov 17, 2010

The commit message mentions haml, just because I first noticed the problem in haml. I tested in ERB on rails 3.0.0 as well.

astupka commented Nov 17, 2010

The following form will remove the deprecation warning in Rails 3:
<%= coffee_script do%>
a = new Bar
<% end %>

mat813 commented May 13, 2011

Actually, I think the coffee_script function should return nil instead. The problem being that it returns a string, and haml mistakenly thinks it should output it.
I found out that doing :

- nil ; coffee_script do
    a = new Bar

solves the problem.

astupka commented Dec 8, 2011

Not needed with rails 3.1

@astupka astupka closed this Dec 8, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment