Docunext

  • About

Quick Overview of the Rails 3.1 Asset Pipeline

October 14th, 2011

The Rails 3.1 asset pipeline has had some twists and turns lately. The community seems to me to be a little overdramatic about the state of affairs, but that's not what this post is about.

I'm writing this post to check in on the last post I wrote about the pipeline: A Problem with the Rails 3.1 Asset Pipeline. In that post, I examined the issue when trying to change the prefix for asset paths with this:

config.assets.prefix = "/s"

It worked for me, but the asset helpers were still using the default path of "/assets". Why was I trying to change the path? Because if I didn't, there would be a controller name clash because I also had a controller named assets_controller.

It was a cool bug to find as I also found a useful patch for it that was never applied to the master branch and I was able to help get it committed. Since then, I haven't actually tried out a fresh version of Rails to see if it works - until today!

I just installed Rails 3.1.1 and created a test application with model named Asset and a controller named AssetsController. After some preliminary testing in both development and production modes, I have come to the conclusion that the asset pipeline in Rails 3.1.1 is working as desired.

More specifically, I'm not experiencing any name collisions - even when I leave config.assets.prefix as the default. Check out these screenshots:

Note that the paths to these assets are as you might expect:

  <link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="/assets/application.js" type="text/javascript"></script>

Additionally, the config.assets.prefix now works with the asset helpers. If I set:

config.assets.prefix = "/s"

then these helpers:

  5   <%= stylesheet_link_tag    "application" %>
  6   <%= javascript_include_tag "application" %>

produce:

FWIW, here's a snibbet of my production.rb config:

  1 Assetstest::Application.configure do
  2   # Settings specified here will take precedence over those in config/application.rb
  3
  4   # Code is not reloaded between requests
  5   config.cache_classes = true
  6
  7   # Full error reports are disabled and caching is turned on
  8   config.consider_all_requests_local       = false
  9   config.action_controller.perform_caching = true
 10
 11   # Disable Rails's static asset server (Apache or nginx will already do this)
 12   config.serve_static_assets = true
 13
 14   # Compress JavaScripts and CSS
 15   config.assets.compress = true
 16
 17   # Don't fallback to assets pipeline if a precompiled asset is missed
 18   config.assets.compile = true
 19
 20   # Generate digests for assets URLs
 21   config.assets.digest = false
 22   config.assets.prefix = '/s'

¥

Yearly Indexes: 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2015 2019 2020