【发布时间】:2020-01-09 12:33:56
【问题描述】:
我创建了简单的 Rails 应用程序。我在下面配置了developemnt.rb(默认设置)。
config.assets.debug = true
config.assets.quiet = true
当我在开发模式下运行应用程序时,出现以下错误。
ActionView::Template::Error (The asset "application.css" is not present in the asset pipeline.)
当我在开发中预编译时。我正在从 public 目录中获取预编译的资产。但是为什么我需要在开发中预编译。
RAILS_ENV=development rails assets:precompile
config/initializer/asset.rb
# 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
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')
Rails.application.config.assets.precompile += %w(application.js application.css test.css)
这里有什么错误?
答案:
调试后我发现config.assets.resolve_with 在开发环境中是如何作为 :manifest 的。
我在 development.rb 中更新为 :environment
【问题讨论】: