Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard way to include Javascript files in app?

Say that I have pulled a fancy.js file from somewhere online, what are the steps that I should take to include it in my Rails 4 application?

Right now I have the following

  1. Move fancy.js to assets/javascripts folder
  2. add //= require fancy to application.js asset pipeline
  3. ???

Are there more steps after 1 and 2, or am I doing this all wrong to begin with?

like image 850
user3277633 Avatar asked Jan 09 '23 12:01

user3277633


1 Answers

Looks like you are on the right path. Take a look inside app/assets/javascripts/application.js

When you created a new app (i.e., rails new app_name), it should have added

//= require_tree .

Simply add references to additional javascript files you wish to include.

EXAMPLE

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require fancy
//= require_tree .

You can find more info on Adding Javascript File to Rails

like image 121
Cyzanfar Avatar answered Jan 12 '23 07:01

Cyzanfar