Example Rails 3.2 app showing how to: use the asset pipeline, scare unicorns, and activate epic rainbows.
Features:
- Laying out SASS files using
@import
instead of the Sprocketsrequire
directive (as per the note in the README for sass-rails) - Laying out JS files using
require_tree
- 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 development.rb
, run 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 @import
and @extend
.
I've included vendor fies directly in the assets directly (e.g. app/assets/javascripts/vendor
), but Rails also looks in vendor/assets
, 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 vendor/assets
and lib/assets
if you wish.