这是默认application.js
:如何根据控制器/操作加载Javascript资源?
//= require jquery
//= require jquery_ujs
//= require_tree .
的CoffeeScript模板有这样的内容: “相关配套控制器这里”
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
对我来说,意味着foo_bar.js.coffee
只应装当使用foo_bar
控制器时。我对吗?
问题是它会加载所有Javascript文件,即使它们不是必需的。另外...我想知道如何有条件地包含JavaScript文件取决于控制器的行为。
+1我同意。这是一个很好的模块化解决方案 – lucapette
很酷,这就是生成的骨架应该如何完成的。行动呢?我的意思是...我想只为特定的动作加载JavaScript ...是否也可以通过简单的方式进行操作? – Cristian