Tidy Stylesheets – dynamically add stylesheets to a view based on controller and action

Ruby on Rails Add comments

Peter 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.

2 Responses to “Tidy Stylesheets – dynamically add stylesheets to a view based on controller and action”

  1. Calvin Says:

    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

  2. Patrick Crowley Says:

    Try using my Styler plugin, guys. :)

    http://the.railsi.st/2007/5/3/styler-stylesheets-made-easy

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in