Why won't Rails find my assets?

BrMcMullin picture BrMcMullin · Mar 14, 2012 · Viewed 13.7k times · Source

When in production mode, rails can't seem to find any precompiled assets from the asset pipeline.

I'm using rails 3.2.0 and ruby 1.9.3 running inside RVM on CentOS. No additional web server is running in conjunction with this application. The application was only recently updated to use the asset pipeline, as it was originally a rails 3.0 app.

After running

rake assets:clean
rake assets:precompile

I see the hashed content in public/assets, as I would expect. The hashes at the end of the files match those I see in the page source.

Yet at runtime, here's what I see for every asset Rails tries to serve:

Started GET "/assets/application-892c6227e631daf9a8e041b1d4d002ec.css" for 75.149.58.169 at 2012-03-14 11:42:43 -0700

ActionController::RoutingError (No route matches [GET] "/assets/application-892c6227e631daf9a8e041b1d4d002ec.css"):

I'm not referring to the folder that each asset is housed in; all references to assets look like these:

//css:
.class {
  background: url(asset.png) no-repeat;
}

//erb:
<%= image_tag "asset.png" %>
<%= link_to "page", :class => "class" %>

Asset pipeline pertinent settings in production.rb:

config.serve_static_assets = false
config.assets.enabled = true
config.assets.compress = true
config.assets.debug = false
config.assets.compile = false
config.assets.digest = true

And lastly, asset settings from config/application.rb:

config.assets.enabled = true
config.assets.version = '1.0'

The user starting the rails server process has read, write and execute permissions on public/assets, so I don't think it's a permissions issue. Have I missed a configuration step?

Edit

I noticed that there are no errors stating that assets are not precompiled, so I tried to access a stylesheet from the web page by appending"/assets/application-892c6227e631daf9a8e041b1d4d002ec.css" to the end of the host path:

http://www.myapp.com"/assets/application-892c6227e631daf9a8e041b1d4d002ec.css"

This worked and the stylesheet opened.

Answer

BrMcMullin picture BrMcMullin · Mar 14, 2012

Further researching of this issue yielded this SO article:

application.css not being served as an asset

It seems

config.serve_static_assets = false

Is an incorrect setting as long as my Rails application is not running behind Apache or nginx