Skip to content

Conversation

@kryzhovnik
Copy link
Contributor

When generating a Rails app with CSS bundling, e.g., rails new myapp --css tailwind --js esbuild, the browser console shows:

GET /assets/tailwindcss net::ERR_ABORTED 404 (Not Found)

The problem:

  1. CSS build tools output to app/assets/builds/application.css

  2. The generated layout has stylesheet_link_tag :app, which expands to link tags for ALL .css files in app/assets/:

  3. The source file application.tailwind.css shouldn't be served directly: only the built output (application.css) should be linked.

This fix:

  • Adds using_css_bundling? helper to detect when CSS bundlers are used
  • Updates layout template to use "application" when --css is present
  • Applies to all CSS bundlers (tailwind, sass, postcss, bootstrap, bulma)

Related: rails/cssbundling-rails#175, rails/cssbundling-rails@1332e42

…present

When generating a Rails app with CSS bundling, e.g., `rails new myapp --css tailwind --js esbuild`, the browser shows:

   GET /assets/tailwindcss net::ERR_ABORTED 404 (Not Found)

The problem:

1. CSS build tools output to `app/assets/builds/application.css`
2. The generated layout has `stylesheet_link_tag :app`, which expands to link tags for ALL .css files in app/assets/:

   <link rel="stylesheet" href="/assets/application-{hash}.css">
   <link rel="stylesheet" href="/assets/application.tailwind-{hash}.css">

3. The source file application.tailwind.css shouldn't be served directly: only the built output (application.css) should be linked.

This fix:
- Adds `using_css_bundling?` helper to detect when CSS bundlers are used
- Updates layout template to use "application" when --css is present
- Applies to all CSS bundlers (tailwind, sass, postcss, bootstrap, bulma)
@guilleiguaran guilleiguaran merged commit 513b6b1 into rails:main Nov 4, 2025
4 checks passed
end

def using_css_bundling?
options[:skip_asset_pipeline] || options[:css]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. You can use the tailwindcss-rails gem without using CSS Bundling, and this change will not include the tailwind.css file that is generated after Tailwind does the build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #56111 to fix this, cc @guilleiguaran

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants