Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Duplicate compiled script using coffee_script helper #4

wants to merge 1 commit into from

2 participants


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

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.


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


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.


Not needed with rails 3.1

@astupka astupka closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/bistro_car/helpers.rb
6 lib/bistro_car/helpers.rb
@@ -12,11 +12,11 @@ def coffee_script_bundle(*bundles)
bundles = bundles.html_safe if bundles.respond_to?(:html_safe)
def coffee_script(&block)
output = BistroCar.compile(capture(&block))
- concat content_tag(:script, <<-JAVASCRIPT, :type => 'text/javascript', :charset => 'utf-8')
+ content_tag(:script, <<-JAVASCRIPT, :type => 'text/javascript', :charset => 'utf-8')
Something went wrong with that request. Please try again.