Rails 5 资源未在生产中加载

Nic*_*ang 5 ruby assets ruby-on-rails asset-pipeline ruby-on-rails-5

我最近在我的 Rails 应用程序中更新了一些包,现在我的资产没有被提供。相反,我收到以下错误:

Failed to load resource: the server responded with a status of 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)

我的资产是预编译的:

资产.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 )
Run Code Online (Sandbox Code Playgroud)

应用程序.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
Run Code Online (Sandbox Code Playgroud)

在告诉我打开编译我的资产之前,请理解这是一个可怕的想法。谢谢你的任何建议

更新:我通过添加以下内容使其工作:

  config.assets.digest = true
Run Code Online (Sandbox Code Playgroud)

到我的config/environments/staging.rb文件。奇怪的是我以前不需要它

tec*_*ams 2

有时,您需要在 staging.rb 或您希望更改反映的任何环境中添加这两种配置。

config.assets.compile = true #set to false by default
config.assets.digest = true 
Run Code Online (Sandbox Code Playgroud)

  • 不建议在生产环境中将编译选项设置为 true。/sf/answers/617943021/ (5认同)
  • 这暴露了您的应用程序中的一个主要漏洞。**不要这样做** (2认同)