assets_helper is the gem that use to include css and javascript by controller name automatically, it mean that include only css and javascript file in the controller that you are running.
Installation
Add this line to your application’s Gemfile:
gem 'assets_helper'
And then execute:
$ bundle
Or install it yourself as:
$ gem install assets_helper
Usage
1. Add before_filter :include_css, :include_javascript
in application_controller.rb:
1 2 3 4 5 |
|
2. Add = yield :asset
n your layout file (exp: application.html.haml):
1 2 3 4 5 6 7 8 |
|
3. Example if you create a controller name homes:
$ rails generate controller homes
4. Go to app/assets/javascripts and create a folder name homes like your controller (homes) you create below. And input javascript file that you use for controller homes in this folder ( app/assets/javascripts/homes ), and no need to include in application.js file.
5. Go to app/assets/stylesheets and create a folder name homes like your controller(homes) you create below. And input css file that you use for controller homes in this folder(app/assets/stylesheets), and no need to include or import in application.css file.
So whenever you run homes controller, it include only css and javascript file that you use for homes controller, and can make your project run fast.