Reputation: 11774
I have a file structure that looks like this:
/stylesheets
application.css.scss
home.css.scss
/office_listings
new.css.scss
index.css.scss
show.css.scss
/neighborhoods
show.css.scss
index.css.scss
and so on. My application includes a require_tree statement. I thought this would compile all of my CSS into the application.css.scss file. But when I visit the page on my local host and inspect the page resources, I not only see my application.css.scss file, I also see every other CSS file I've made. The same holds true for my javascript files.
I tried running rake assets:clean and manually deleting any files cached in my public folder just in case it was an issue with rake assets:precompile which I ran a few times, but I still have the same issue.
Upvotes: 0
Views: 81
Reputation: 5622
This is the expected behavior if you are running the Rails application in the development
environment (the default). By default, development
is configured with config.assets.debug
set to true
, which causes all asset files to be served individually to ease debugging - the browser's CSS inspector will show you the correct file a rule originates from, rather than always pointing to the single generated single.
However, if you precompile and run the app in the production
environment, only one file is generated and served. You can test this by running the following commands:
RAILS_ENV=production rake assets:precompile
RAILS_ENV=production rails server
If you visit your site now, you should see only a single application.css
file with all of your stylesheets combined. (Make sure your config/environments/production.rb
file contains config.serve_static_assets = true
- otherwise, you won't get any stylesheet at al and will just see unstyled HTML.)
For more details, I recommend the section "Turning debugging off" in the Rails guide on the asset pipeline.
Upvotes: 2
Reputation: 38645
If you have config.assets.debug = true
in your config/environments/{environment}.rb
where {environment}
could be development
, production
etc, then all of your asset files will be expanded like you've mentioned.
Change that line to config.assets.debug = false
and you will only see application.css
and application.js
.
Upvotes: 1