Ruby on Rails 4: How to include Javascript files in Rails web application?

后端 未结 4 1400
余生分开走
余生分开走 2020-12-14 08:01

I am building a Rails 4 web application and I want to include some .js files into my application. Is it possible to directly add JavaScript file to my Rails ..app/asse

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 08:25

    Taking a look at the application.html.erb file, you'll see that the application.js was referenced via:

    <%= javascript_include_tag "application", "data-turbolinks-track" => true  %>
    

    So when I had this challenge, what I did was: add this script in the file where I wanted to reference my custom javascript, but this time I modified the parameter. So instead of "application," I have this:

    <%= javascript_include_tag "customjsFile", "data-turbolinks-track" => true  %>
    

    Hope this helps.

提交回复
热议问题