Tidy Stylesheets – dynamically add stylesheets to a view based on controller and action
Ruby on Rails Add commentsPeter Harkins has a great post on how to split stylesheets based on controller and action. The required code is very short and easy to integrate. It will add a few levels to your stylesheet directory structure, but any Rails-savvy developer should be able to very quickly figure out what’s going on.
This is very similar to how Symfony handles stylesheet selection, except it is done via configuration files. This is one of the very few things I like about Symfony, and I’m happy to see that someone has ported the functionality to Rails.
If you know of a better (or different) way to manage stylesheet complexity, please post a comment.
July 11th, 2007 at 11:00 am
I think the only problem with doing this would be the extra HTTP traffic generated from the multiple stylesheets, but the solution looks easy enough to mix in with the asset packager plugin:
http://synthesis.sbecker.net/pages/asset_packager
– Calvin
July 11th, 2007 at 1:55 pm
Try using my Styler plugin, guys.
http://the.railsi.st/2007/5/3/styler-stylesheets-made-easy
April 10th, 2011 at 6:46 am
GF1O7j Wow! That’s a really neat answer!