【发布时间】:2017-03-02 01:29:00
【问题描述】:
我最近更新了我的 Rails 应用程序中的一些包,现在我的资产没有被提供。相反,我收到以下错误:
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
在告诉我打开编译我的资产之前,请理解这是 horrible idea。谢谢你的建议
更新:我通过添加:
config.assets.digest = true
到我的config/environments/staging.rb 文件。奇怪的是我以前不需要它
【问题讨论】:
-
你升级了什么?你能 git bisect 找到导致问题的包并将其发布到这里吗?
-
是的,我的意思是我做了一个捆绑升级,它基本上更新了一堆包。您可以在此处查看列表:github.com/NicholasLYang/blog/commit/…
-
返回 404 的 URL 是什么,您在哪里找到该 URL?资产被编译成公共/资产。无论您尝试请求什么 URL,如果它不在该文件夹中,它将 404。你在运行 rake assets:precompile 吗?
-
仅供参考,您永远不想
bundle updateGemfile 中的所有内容。您通常一次执行 1 个 gem,在执行此操作之前,您会阅读发行说明,以便了解您需要担心的任何重大更改。 -
@Anthony 是的,你是对的。我搞砸了。 @mahemoff Capistrano 确实预编译了资产,但是是的,我在部署之前确实运行了
rake assets:precompile。
标签: ruby-on-rails ruby ruby-on-rails-5 asset-pipeline assets