rails - application.css asset not found in production mode

前端 未结 4 1757
夕颜
夕颜 2021-01-31 16:38

I\'m upgrading an application to use the asset pipeline.

I\'ve got the css assets compiling into an application css file but they not being found when I run the applicat

4条回答
  •  無奈伤痛
    2021-01-31 17:03

    Rails by default doesn't serve assets under public. See your production.rb:

      config.serve_static_assets = true
    

    Change that to true and you're good to go. (Note: you don't want that to be true in production, remember to change it back before deploying!)

    See Configuring Rails Applications for details.

    In rails 6, in the default production.rb there should be a line

    config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
    

    So run your server with

    RAILS_SERVE_STATIC_FILES=true rails server -e production
    

    or set config.public_file_server.enabled=true in production.rb. See answers below for rails 4 and 5.

提交回复
热议问题