简体   繁体   中英

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.

您的模板应命名为.js.coffee

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

不,由于咖啡可以编译为js,因此您需要在coffee或js之间进行选择。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM