好的,我已经阅读了很多关于Rails 3.1新资产管道的信息,但是我没有找到一个适当的答案来解决我的疑问。
我根据我正在渲染的视图#动作来按需加载我的.js文件。我这样做是为了防止错误的绑定并加载小的.js文件。
candidate_opportunities#index
$(".sortable_drag_n_drop").sortable({
update: function(event, ui) {
$.post('/candidate_opportunities/sort', $(this).sortable('serialize'));
},
handle: 'span'
});
candidate_companies#index
$(".sortable_drag_n_drop").sortable({
update: function(event, ui) {
$.post('/candidate_companies/sort', $(this).sortable('serialize'));
},
handle: 'span'
});
$(".sortable_drag_n_drop").disableSelection();
现在什么是最好的解决方案?
- 我应该更改我的绑定,并让Sprockets使用
//= require_tree .
编译所有的.js文件吗? - 还是应该根据我的视图来加载.js,这样我就不会得到一个巨大的application.js?