Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No route matches [GET] /assets

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

Adding to what Ryan said above, the Rails asset pipeline guide describes how to setup Apache or nginx to serve the static assets for you.

http://guides.rubyonrails.org/asset_pipeline.html

You really should setup nginx or Apache to serve static assets, as they're much better optimized for this task than mongrel/thin/unicorn.


Just solved the same problem. In my case Ryan's answer was not helpful. Bratsche pointed to the Rails Guides, unfortunately this didn't work for me too. However the resource was helpful. So I took Nginx configuration from there and added the root directive, pointing to the public directory. Without this it doesn't work.

   # serve static assets
   location ~ ^/assets/ {
     expires 1y;
     root  /path/to/my/cool_project/public;
     add_header Cache-Control public;

     add_header ETag "";
     break;
   }

Restart nginx, and that's it.


In rails 5, the config.serve_static_files option has changed, so now you need to have

config.public_file_server.enabled = true

to serve assets locally.


Indeed you didn't need to modify any default configs. You just recompile assets file again.

remove public/assets

1.rake assets:clobber RAILS_ENV=production

assets compile

2.rake assets:precompile RAILS_ENV=production

3.restart server,eg(nginx)


Rails 4.2 has added/changed this line in your config/environments/ staging.rb and production.rb files:

config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

If RAILS_SERVE_STATIC_FILES is not set, and you are service assets from your Rails server (like with Unicorn), then it will default to "false", and the RoutingError will occur.

This is an easy fix:

config.serve_static_files = true

try below code:

config/environments/production.rb

config.assets.compile = true

then run command:

RAILS_ENV=production rake assets:precompile

then push all compiles files and manifest file to server.