Rails 3.1: The shared directory no longer serves js assets. How to load additional js file after page loading?

I am using a jQuery plugin that downloads another js file from the server after the page loads initially. Since all js assets are merged in Rails 3.1, and the public directory is not used to serve js assets, how can I link to this file? Where can I say?

+3
source share
2 answers

Each resource in the Sprockets download path is available at runtime. You can see your download path in the Rails console with

Rails.application.config.assets.paths

You can add boot paths to the initializer:

Rails.application.config.assets.paths << your_load_path

//// . . assets/directory .

, apps/assets/javascripts/myscripts/hello.js, http://mydomain.com/assets/myscripts/hello.js.

- . , , Sprockets require provide .

+3

, . Rails 3.1 JavaScript CSS . Sprockets.

. /app/assets/javascripts/application.js Sprockets, Sprockets, .

application.js Rails- :

// FIXME: Tell people that this is a manifest file, real code should go into discrete files
// FIXME: Tell people how Sprockets and CoffeeScript works
//
//= require jquery
//= require jquery_ujs
//= require_tree .

JavaScript, Sprockets , , application.js, . , , require_tree, JavaScript.

, Sprockets. , .

require_tree app/assets/javascripts. , , , . require_tree require_path.

, Sprockets , require filename JavaScript.

+1

All Articles