Skip to content

Instantly share code, notes, and snippets.

@dce
Created September 21, 2011 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dce/1232328 to your computer and use it in GitHub Desktop.
Save dce/1232328 to your computer and use it in GitHub Desktop.

Rails 3.1 Asset Pipeline

  • The new asset pipeline in Rails 3.1 makes assets first class citizens in Rails
  • Assets now in app/assets rather than public (also lib/assets, vendor/assets)
  • Asset files can inline other asset files using requires
  • Asset packages are defined in manifests
/*
 *= require blueprint/reset
 *= require blueprint/typography
 */
  • Gem dependencies can provide asset files for the application to use
  • In production mode, generated files include an MD5 hash as part of the file name
  • At the heart of the pipeline is Sprockets 2.0
  • Sprockets will allow any number of filters to be used with asset files
    • run a file through SASS and ERB by naming it stylesheet.css.scss.erb
body {
  background: url(<%= asset_path "sunshine-rainbows-and-lollipops.png" %>);
  /* You have to use ERB to link to asset pipelined resource */
}
  • CoffeeScript and SASS are now included in the default template
    • Invoke w/ application.js.coffee, application.css.sass
  • support for JS minification comes built-in with Rails via UglifyJS

http://guides.rubyonrails.org/asset_pipeline.html
https://github.com/sstephenson/sprockets
http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment