Rails 5 Assets Not Loading in Production

心不动则不痛 提交于 2020-06-25 04:14:13

问题


I recently updated a few packages in my Rails application and now my assets aren't being served. Instead, I get the following error:

Failed to load resource: the server responded with a status of 404 (Not Found)

My assets are precompiled:

assets.rb

# Be sure to restart your server when you modify this file.

# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'

# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
Rails.application.config.assets.precompile += %w(ckeditor/*)
Rails.application.config.assets.precompile += %w(ckeditor/config.js)
Rails.application.config.assets.precompile += %w( *.js ^[^_]*.css *.css.erb )

application.rb

require_relative 'boot'

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)


module DeployTest
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.
    config.assets.precompile += Ckeditor.assets
    config.assets.precompile += %w( ckeditor/* )
    config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
    config.active_record.default_timezone = :local
    config.time_zone = 'Eastern Time (US & Canada)'
  end
end

Before telling me to turn on compiling my assets, please understand that this is a horrible idea. Thank you for any advice

UPDATE: I got it to work by adding:

  config.assets.digest = true

to my config/environments/staging.rb file. Weird how I didn't need it before


回答1:


At times you need to add both of these configurations in staging.rb or whichever environment you want the changes to reflect on.

config.assets.compile = true #set to false by default
config.assets.digest = true 


来源:https://stackoverflow.com/questions/42545262/rails-5-assets-not-loading-in-production

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