user2630970
user2630970

Reputation: 153

How to respond with coffee script

How can I respond with coffee flavoured JS?

def new
  respond_with { |format| format.js }
end

# new.js.coffee.erb
$('#blah_' + @blah.id).something ->
  etc...

This breaks, though: missing template. I need to choose between coffee or erb, but I want both.

Upvotes: 0

Views: 163

Answers (3)

Marc Baumbach
Marc Baumbach

Reputation: 10473

If you suffix your template with .js.coffee you'll get both ERB and CoffeeScript capabilities.

This is highly confusing because most templates you define which pre-processors you want your templates to run through by adding extensions. See this issue on GitHub: https://github.com/rails/coffee-rails/issues/36

Upvotes: 2

Raindal
Raindal

Reputation: 3237

Your template should be named .js.coffee.

Upvotes: 3

Agis
Agis

Reputation: 33636

No, you need to choose between coffee or js, since coffee compiles to js.

Upvotes: 0

Related Questions