I have multiple files in my app/assets/javscripts
folder, application.js.erb
, page.js.erb
, sections.js.erb
& scraped.js.erb
.
Rails loads them all in my layout with <%= javascript_include_tag "application" %>
in application.html.erb
layout. Which is called from the PagesController
.
I do not want scraped.js.erb
to be loaded at all & sections.js.erb
I would like to only be loaded from the SectionsController
.
From my understanding (after reading http://guides.rubyonrails.org/asset_pipeline.html ) that's how the asset pipeline worked. That if called from the PagesController
it would load application.js.erb
& page.js.erb
but obviously that's not the case.
Am I doing something wrong? Could someone explain to me how the asset pipeline works? And how I can only use select assets rather than all of them?
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
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.