如何使用javascript_include_tag从vendor / assets / javascripts添加特定于控制器的javascript?

时间:2013-10-02 20:50:31

标签: javascript ruby-on-rails assets form-helpers vendor

我有rails项目和视图new.html.slim

我试过以下:

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

404 Not Found

仍然获得handelbars.runtime.js

所有vendor/assets/javascripts/图书馆的正确途径是什么?

我不会在application.js

中包含handelbars.runtime.js

更新

如果我在浏览器中查看路径:

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

但我也得到了:

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

也只是为了测试:

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

1 个答案:

答案 0 :(得分:2)

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

= javascript_include_tag "handlebars.runtime"

如果您将其放在视图的末尾,那么它将包含在文档中。如果您希望将其包含在头部或底部,请使用yield <symbol>功能来实现此目的。例如,如果我的布局中有<%= yield :head %>,我可以将上面的include标记调用放入content_for:

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