我最近更新了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
在让我开启编译资产之前,请了解这是一个糟糕的想法。感谢任何建议。
更新:我通过添加以下内容使其工作:
config.assets.digest = true
添加到我的config/environments/staging.rb
文件中。奇怪的是之前我不需要它。
digest
选项(应该这样做,并且在生产中默认打开),路径将不是application.css。它将是一些随机名称,例如application-0f9j48f90490fj3409.css。请查看您的public/assets文件夹。生成的HTML将链接到摘要文件名,因此您缺少的application.css是预期的,而不是问题。只需使用标准的Rails标记从HTML链接到资产即可。 - mahemoff<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
。 - Nicholas Yang