How to manage CSS Stylesheet Assets in Rails 3.1? How to manage CSS Stylesheet Assets in Rails 3.1? ruby-on-rails ruby-on-rails

How to manage CSS Stylesheet Assets in Rails 3.1?


This is how i solved the styling issue: (excuse the Haml)

%div{:id => "#{params[:controller].parameterize} #{params[:view]}"}    = yield

This way i start all the page specific .css.sass files with:

#post  /* Controller specific code here */  &#index    /* View specific code here */  &#new  &#edit  &#show

This way you can easily avoid any clashes.

Hope this helped some.


@nathanvda: sure...

We make use of multiple layout files. So in our app/views/layouts, instead of having just application.html.haml (we use HAML), we actually ignore the application layout and use 3 custom layouts:

admin.html.haml (admin section views only)

registered.html.haml (registered/signed in users views only)

unregistered.html.haml (unregistered/unsigned in users views only)

So at the top of my admin.html.haml file I will have my stylesheet link tags to a separate admin.scss (we use SCSS) manifest. That manifest will load any necessary sub-stylesheets just for the admin section. This allows us to specify rules just for the admin section while also making use of common styles. For instance, we use jquery-ui throughout the site, so the styles associated with jquery-ui sit in their own stylesheet and we include them in the manifests for all 3 css manifest files.

This solution doesn't give you a single CSS file that can be cached, but it ends up giving you 3 CSS files, each of which can be cached. This allows a tradeoff between performance and some flexibility in organizing CSS rules so we don't have to worry about CSS rule collisions.