Duplicate compiled script using coffee_script helper #4

Closed
wants to merge 1 commit into from

2 participants

@astupka

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

  1. rails g controller Foo index

  2. add bistro_car to Gemfile

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

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

  4. Comment out the action_mailer setting in development.rb

  5. Edit index.html.erb to contain <% coffee_script do%> a = new Bar <% end %>
  6. The compiled coffee script will be duplicated in the HTTP response from http:/localhost:3000/index
@astupka

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

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

@mat813

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
  :plain
    a = new Bar

solves the problem.

@astupka

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