Saturday 24 March 2012

Ruby on Rails : How to include a page specific JavaScript file in Rails 3.1?

Rails 3.1 application has a new effective way to include a JavaScript file for a particular page without compromising the loading time by using Asset pipeline.


You all know that  in previous versions of Rails, all assets were located in subdirectories of public such as images,javascripts and stylesheets. With the asset pipeline, the preferred location for these assets is now the app/assets directory.Assets can still be placed in the public hierarchy. Any assets under public will be served as static files by the application or web server.

In production, Rails precompiles these files to public/assets by default. The precompiled copies are then served as static assets by the web server. The files in app/assets are never served directly in production.