简体   繁体   中英

How to add a controller-specific javascript from vendor/assets/javascripts using javascript_include_tag?

I have in rails project and a view new.html.slim :

I tried following:

= javascript('app/vendor/assets/javascripts/handelbars.runtime.js')
= javascript('../../../vendor/assets/javascripts/handelbars.runtime.js')
= javascript('./vendor/assets/javascripts/handelbars.runtime.js')

But still getting 404 Not Found for handelbars.runtime.js

What is the right path for all vendor/assets/javascripts/ libraries?

I wouldn't include handelbars.runtime.js in application.js

Update:

If I look into the path in browser:

http://localhost:3000/javascripts/vendor/assets/javascripts/handelbars.runtime.js

But I get also:

Routing Error
No route matches [GET] "/javascripts/vendor/assets/javascripts/handelbars.runtime.js"

Also just to test:

Routing Error
No route matches [GET] "/vendor/assets/javascripts/handelbars.runtime.js"  

http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-javascript_include_tag

= javascript_include_tag "handlebars.runtime"

If you put this at the end of your view it will be included in the document at that point. If you want it to be included in the head or at the bottom use the yield <symbol> functionality to achieve that. for instance if I have a <%= yield :head %> in my layout I can put the include tag call above into a content_for:

= content_for :head do
    = javascript_include_tag "handlebars.runtime"

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM