Rails 404 error for Stylesheet or JavaScript files

大城市里の小女人 提交于 2019-12-01 11:54:31

The error message looks like your Rails app is getting the request for a static file. Rails 3 does not serve static files by default, since the webserver can do so much better. You should check your webserver's configuration. It should be configured to first look, if a static file exists in the public directory for a request and only forward the request to the Rails app, if there's no static file.

Alternatively, you can enable Rails to also serve static files with config.serve_static_assets = true in config/environments/production.rb. However, this is not recommended in production, since you really shouldn't waste processing resources of a Rails app just for serving static files. Better tell the webserver to do so.

I fixed this problem by running this command:

RAILS_ENV=production rake assets:precompile

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

My environment is Nginx + Unicorn + Rails4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!