How to manage CSS Stylesheet Assets in Rails 3.1?

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

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.

I should add that we now need to explicitly call which layout we are using since we don't use the default application layout. This can be done for the entire controller or for each action individually. We have also written a helper to check whether there is a current signed in user and then to select the appropriate layout.

– Ben Aug 25 at 11:33.

I have a post about this on my website: Leveraging Rails 3.1, SCSS, and the assets pipeline to differentiate your stylesheets And check out this answer to another question: Using Rails 3.1 assets pipeline to conditionally use certain css Hope this helps. Best regards, Lasse.

The way I've been doing it so far is to have two seperate folders a/ and u/ where a/ is for the admin view and u/ is for the user view. Then in the layout I point to the appropriate application. Css with assets/u/application.

Css(js). Bit of a pain having to move the auto generated files each time but a lot less than having to require each file individually in the manifest.

1 Thanks for the response. The way I decided to do it was to use two different layouts, one for the admin system and one for the main site. Each layout links to different css manifest files.

– Ben May 24 at 14:41 1 @Ben: Could you please explain this in greater detail in a real answer? I am really interested in how you did this. Thank you.

– nathanvda Aug 6 at 16:33 @nathanvda: I think he means something like this – Lasse Bunk Sep 5 at 20:49.

I use something like application.html. Erb "> show.html. Erb content_for :body_id do page_specific_body_id end.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions