Standard way to include javascript files in an application?

Tell me I pulled the fancy.js file from the Internet, what steps should I take to include it in my Rails 4 application?

Now i have

  • Move fancy.js to assets / javascripts folder
  • add // = requires pulling to application.js pipeline
  • ???

Are there a few more steps after 1 and 2, or am I doing it all wrong?

+4
source share
2 answers

You seem to be on the right track. Take a look insideapp/assets/javascripts/application.js

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

//= require_tree .

Just add links to additional javascript files that you want to include.

Example

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

Javascript Rails

+6

Rubygems . fancybox2-rails.

gem 'fancybox2-rails', '~> 0.2.8'

application.js :

//= require jquery
//= require fancybox

script:

<%= javascript_include_tag "fancybox" %>

css:

/*
 *= require_self
 *= require fancybox
 *= require_tree .
 */

Gemified- , , . , , , .

, , lib/assets, app/assets, , .

, , , ( Heroku), ( ). .

+3

All Articles