Rails 5资产未在生产中加载 [英] Rails 5 Assets Not Loading in Production

查看:74
本文介绍了Rails 5资产未在生产中加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在Rails应用程序中更新了一些软件包,但是现在无法使用我的资产.而是,出现以下错误:

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)

我的资产已预编译:

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

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

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

推荐答案

有时,您需要将这两个配置都添加到staging.rb或要反映更改的任何环境中.

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 

这篇关于Rails 5资产未在生产中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆