Managing asset files

The entry point of the assets:

  1. The application.js
  2. The application.css

It is an entry point because in each file it includes the other files into the assets.

require name     <-- means include that file.
require_tree .   <-- means include all the files in the current directory.

There is a list of folders the asset pipeline will search.

/app/assets/
/lib/assets/
/vendor/assets/

Actually we can use the file others than the “application” name. Just clone the application.css and .js into a new file and update the asset include name in the views/layout/application.html.erb file.

Note: How about we want to include specific controller assets only?

  1. Remove the require_tree . in the application js and css file.
  2. Use <%= javascript_include_tag params[:controller] %> when needed
  3. or <%= stylesheet_link_tag params[:controller] %> when needed

What’s next? We’re going to take a look at “Creating gallery home page”.

overlaied image when clicked on thumbnail

Makzan | Ruby on rails 101 | Table of Content