Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  183] [ 6]  / answers: 1 / hits: 72979  / 10 Years ago, mon, march 10, 2014, 12:00:00

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/assets/javascripts folder and add reference in application.js like this?



//= customejsfile.js 


Is this the right way? If yes, is it possible for me to follow the same steps in adding jQuery and Bootstrap library?



Any help is appreciated.


More From » jquery

 Answers
36

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.


[#72073] Friday, March 7, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daquanmilesw

Total Points: 57
Total Questions: 102
Total Answers: 110

Location: Wallis and Futuna
Member since Sat, Aug 6, 2022
2 Years ago
daquanmilesw questions
;