No route matches [GET] /assets

Kyle Decot picture Kyle Decot · Oct 20, 2011 · Viewed 81.5k times · Source

I have a Rails app that I'm trying to test in the production environment. I ran RAILS_ENV=production rake assets:precompile which generated all of my assets in /public/assets. The problem is that when I start my app w/ RAILS_ENV=production rails s thin I get:

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

This file does exist though at /public/assets/application-eff78fd67423795a7be3aa21512f0bd2.css.

Any thoughts as to why I'm getting this RoutingError?

Answer

Ryan Bigg picture Ryan Bigg · Oct 20, 2011

In production mode, Rails will not be responsible for serving static assets. Therefore, you are getting this error. Thin won't do it either, since it's just a wrapper around Rails.

This is controlled by this setting in config/environments/production.rb in your application:

config.serve_static_files = false

Or in Rails 5:

# config/environments/production.rb
config.public_file_server.enabled = true

Or set ENV['RAILS_SERVE_STATIC_FILES'] to true.

You can either set to that true or use a real server like Apache or Nginx which will serve the static assets. I suspect Pow may also do it.


If you're on Heroku, they recommend the use of the rails_12factor gem which enables this setting by default. Place the gem into a production group in your Gemfile, like this:

group :production do
  gem 'rails_12factor'
end