You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails 5.2开发环境Asset Pipeline失效问题排查

解答:Rails开发环境资产找不到的问题

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 08:37:39