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

后端 未结 4 1402
余生分开走
余生分开走 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:07

    The right way to include your files is:

    //= require customejsfile
    

    in your application.js file. What's more, by default you have

    //= require_tree .
    

    which requires all js files from assets/javascript path, so you don't have to type it on your own (and you shouldn't, or you'll have your file included twice). JQuery library is included by default (and it comes from jQuery gem). If you want Bootstrap, then you can do it this way or use one of existing gems, like bootstrap-generators or twitter-bootstrap-rails.

提交回复
热议问题