Just installed rails 3.1 rc1 and am trying to grok the best way to manage javascript with the new asset pipeline By default all coffeescript is compiled into a single application.js file, this is a good thing.
Each seperate coffee script file is appended to the js file and wrapped in an anonymous function which is executed via the call method A common scenario would be to use some jquery to turn various forms into ajax forms, update UI, etc...
Many of these scripts will be specific to a controller or action, I am trying to grok the conventional way to handle this, since everything is wrapped in an anonymous function how do I only execute just the code for a particular controller / action, by default all of the anonymous functions are being executed
I did play around with some hacks where I load the controller and action name into js variables and then in coffeescript check those to conditionally run code, I don t like that very much
my initial thought was that each coffee file would contain a js namespace/object and I would call the specific ones from the view, going to spike this using the default_bare = true configuration
请参阅如何在Rails3.1中为CoffeeScript使用选项”--bare“
编辑
环顾四周:这看起来可能是正确的方法-Rails 3.1和Coffeescription出现“找不到变量”错误