Example Rails 3.2 app showing how to: use the asset pipeline, scare unicorns, and activate epic rainbows.
- Laying out SASS files using
@importinstead of the Sprockets
requiredirective (as per the note in the README for sass-rails)
- Laying out JS files using
- JST and eco templates w/ Backbone
- data-uri'd assets
- Referencing an asset from both CSS and JS (see the
link[rel]in the app layout)
- Tasteful use of Comic Sans with a subtle yet beautiful text-shadow
bundle install rake assets:precompile rails s
You'll see the bottom of
development.rb has two lines copied from
production.rb to test and demonstrate production asset compilation.
To change this back to normal behaviour simply comment out the two lines at the bottom of
rake assets:clean, and restart the rails server.
If you're running with
config.assets.compile = false and run
rake assets:compile you'll need to restart the server to see changes. This is because the
public/assets/digest.yml is loaded only on application boot.
As per the note in the README for sass-rails–the Gem that Rails loads from your Gemfile which adds SASS support to the asset pipeline–you should never use the Sprockets
require directives in your CSS.
SASS (when used through
sass-rails) can do everything the Sprockets directives can with the bonus of playing well with
I've included vendor fies directly in the assets directly (e.g.
lib/assets, and Gem lib paths. I like to take ownership of all assets, third-party or otherwise, and keep them together in
app/assets. This is just personal preference and you can place them in
lib/assets if you wish.