Re: Good solution for managing stylesheets

Jamis Buck
Fri, 19 Aug 2005 21:36:37 -0000

On Aug 19, 2005, at 3:31 PM, Jeffrey Moss wrote:

> Does anybody figure they have the perfect solution for managing
> stylesheets when using layouts and partials?
>
> I''d like a way for each partial to automatically include something
> in the header section of the layout, when it is used. Right now I
> just have the layout setup to include 3 stylesheets, one called
> "default", another called the controller name, and another called
> the action name, but this of course has limitations.
>
> I thought there was something in the works to handle this (having
> things appear in the header that were called in a template or
> partial), was that idea scrapped? I imagine it presents a few
> problems, I mean it''s sortof dirty to automatically include
> stylesheets based on what the page is composed of, I may need to
> just switch to a controller-based add_stylesheet macro or something...
>

I''ve done the following in the past. Anytime I have another
stylesheet I want used (in a partial, for instance), I just do:

   <% (@stylesheets ||= []) << "my_stylesheet" %>

And then in the master layout:

   <% stylesheet_link_tag(*@stylesheets) if @stylesheets %>

It''s simple, easy to extend, and doesn''t require any special
infrastructure.

- Jamis