Docunext


A Problem with the Rails 3.1 Asset Pipeline...

September 19th, 2011

I've run into an error with the Rails 3.1 asset pipeline where one of my controllers happens to be named AssetsController:

Routing Error

No route matches {:action=>"show", :controller=>"assets", :id=>"web-app-theme/base", :format=>"css", nil=>:request}

Hmmm. What to do? First, an explanation.

The Rails 3.1 Assets "Controller"

Here's what's happening:

  • I have an assets controller, so I also have the following in my config/routes.rb file: resources :assets.
  • I am using the new asset pipeline in Rails 3.1.
  • I tried renaming the assets path like so: config.assets.prefix = "/s", but it apparently didn't work.
  • I can confirm its a name collision because if I comment out the resources line in config/routes.rb, there is no error.

Working Around the Assets Controller Name Collision

I figure there are a few options:

  • Namespace my assets controller to be Accounts::AssetsController. I had originally opted agains that for simplicities sake, but it might be a solid solution. I do not want to namespace my models though.
  • Find another configuration setting to alter the "assets" name for the asset pipeline. There is config.assets.manifest, but that is for pre-compiling assets, not accessing them.

Ultimately it seems that the nexus of this problem is that the tag helpers do not use the custom config.assets.prefix value. Thankfully, there has been a commit to fix it. Alas, it seems to have been overlooked in recent tags and releases.

As a quick workaround, I'm not using the tag helpers, just accessing the css files directly.

UPDATE: Hooray! Rails developer spastorino pulled request 3092 to fix this issue. That is so great. FWIW - my initial experience working with the Rails development community has been positively impressive.

¥

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