1

我的文件app/assets/javscripts夹中有多个文件,application.js.erb, page.js.erb, sections.js.erb& scraped.js.erb

<%= javascript_include_tag "application" %>Rails 使用in layout将它们全部加载到我的布局中application.html.erb。从PagesController.

我根本不想scraped.js.erb加载 &sections.js.erb我只想从SectionsController.

据我了解(在阅读http://guides.rubyonrails.org/asset_pipeline.html之后),资产管道就是这样工作的。如果从它调用PagesController它会加载application.js.erb&page.js.erb但显然情况并非如此。

难道我做错了什么?有人可以向我解释一下资产管道是如何工作的吗?以及我如何只能使用选择的资产而不是全部?

4

1 回答 1

2

Check your manifest file, in assets/javascript you got the file application.js, it contains //= require_tree . which include during compilation all files of the directory tree.

If you want to exclude some files you can either require your files one by one: // require my_file, either create sub directories in your javascript directory and use //= require_directory my_directory

Read more http://guides.rubyonrails.org/asset_pipeline.html

于 2013-05-04T07:54:30.933 回答