Ruby on rails or simply Rails is a wonderful web application framework, written in Ruby. It provides services for a web page designing. It has won tech geeks votes for its faster services in terms of developing a website because of its user-friendly features, reduced complexity, and thus improving its efficiency allover. One such feature for RoR is The Asset Pipeline.
The asset pipeline is a very powerful feature that Rails offers, to solve a wide range of problems related to web designing.
The Asset Pipeline :
The asset pipeline is technically no longer a core feature of Rails 4, it has been extracted out of the framework into the sprockets-rails gem.
The asset pipeline is enabled by default.
We can disable the asset pipeline while creating a new application by passing the –skip-sprockets option.
rails new appname –skip-sprockets
Rails 4 automatically adds the sass-rails, coffee-rails and uglifier gems to your Gemfile, which are used by Sprockets for asset compression:
Using the –skip-sprockets option will prevent Rails 4 from adding sass-rails and uglifier to Gemfile, so if you later want to enable the asset pipeline you will have to add those gems to your Gemfile. Also, creating an application with the –skip-sprockets option will generate a slightly different config/application.rb file, with a require statement for the sprockets railtie that is commented-out. You will have to remove the comment operator on that line to later enable the asset pipeline:
# require “sprockets/railtie”
config.assets.css_compressor = :yui
config.assets.js_compressor = :uglifier
How to Use the Asset Pipeline :
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 when config.serve_static_files is set to true. You should use app/assets for files that must undergo some pre-processing before they are served.
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.
Controller Specific Assets :
Precompiling Assets :
Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline.
Compiled assets are written to the location specified in config.assets.prefix. By default, this is the /assets directory.
You can call this task on the server during deployment to create compiled versions of your assets directly on the server. See the next section for information on compiling locally.
The rake task is:
$ RAILS_ENV=production bin/rake assets:precompile
Capistrano (v2.15.1 and above) includes a recipe to handle this in deployment. Add the following line to Capfile:
This links the folder specified in config.assets.prefix to shared/assets. If you already use this shared folder you’ll need to write your own deployment task.
It is important that this folder is shared between