Rails 5.2开发环境Asset Pipeline失效问题排查
Alright, let's walk through exactly what's causing this issue and why your fix worked:
1. 开发环境资产管道的默认行为
By default, when config.assets.debug = true (your setup), Rails' development environment does not precompile assets. Instead, it loads raw files directly from your app/assets directory, and even splits CSS/JS into individual files to make debugging easier.
For this to work, config.assets.resolve_with should be set to :environment—this tells Rails to look for assets directly in your configured asset paths (like app/assets, node_modules) instead of relying on a precompiled manifest file.
2. Why resolve_with: :manifest broke things
When resolve_with is set to :manifest, Rails looks for the manifest.json file (generated only after running rails assets:precompile) in public/assets. This file maps logical asset names (like application.css) to their precompiled, fingerprinted versions.
Since you hadn't run precompile initially, this manifest.json didn't exist. Rails couldn't find the mapping for application.css, hence the error: "The asset 'application.css' is not present in the asset pipeline."
3. Why precompiling "fixed" it (but wasn't the right solution)
Running RAILS_ENV=development rails assets:precompile generated the manifest.json and compiled your assets into public/assets. Rails could now use the manifest to find the precompiled application.css—but this defeats the purpose of the development environment!
In development, you want changes to your raw app/assets files to show up immediately in the browser. With precompiled assets, you'd have to re-run assets:precompile every time you edit a CSS/JS file, which is a huge workflow blocker.
4. Your assets.rb configuration: Any issues?
Looking at your config/initializers/assets.rb code:
Rails.application.config.assets.precompile += %w(application.js application.css test.css)
This line is redundant—Rails already includes application.js and application.css in the default precompile list. It doesn't cause your error, but it's unnecessary. The real culprit was the misconfigured resolve_with setting.
5. The core mistake in your original setup
Setting config.assets.resolve_with = :manifest in the development environment is incorrect. This is a production environment setting—production relies on precompiled assets and the manifest to serve assets efficiently with fingerprinting for cache busting.
Development environment needs resolve_with: :environment to load raw, uncompiled assets directly from your asset paths, no precompile required.
内容的提问来源于stack exchange,提问作者Praveenkumar

