Rails 404 error for Stylesheet or JavaScript files

后端 未结 2 1509
感情败类
感情败类 2021-01-15 04:16

Rails can\'t load (404 error) CSS & JS files on production but has no problem loading them in development.

I\'m using Capistrano for deployment and running Rails

相关标签:
2条回答
  • 2021-01-15 04:56

    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

    0 讨论(0)
  • 2021-01-15 05:04

    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.

    0 讨论(0)
提交回复
热议问题