Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Example Rails 3.2 app showing how to: use the asset pipeline, scare unicorns, and activate epic rainbows.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 script
Octocat-spinner-32 vendor
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 config.ru
README.md

Asset Pipeline Example

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 Sprockets require 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

Running

bundle install
rake assets:precompile
rails s

Re-enabling development asset compilation

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.

Reloading assets after precompilation

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.

Discussion points

Avoiding Sprockets directives in SASS

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.

Vendor and lib assets

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.

Something went wrong with that request. Please try again.