# .css.erb files ?

**URL:** <https://discuss.rubyonrails.org/t/css-erb-files/28719>\
**Category:** rubyonrails-talk\
**Created:** [April 29, 2008, 2:42pm UTC](https://discuss.rubyonrails.org/t/css-erb-files/28719 "2008-04-29T14:42:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 29, 2008, 2:42pm UTC](https://discuss.rubyonrails.org/t/css-erb-files/28719/1 "2008-04-29T14:42:50Z")

</div>

hi, with Rails 2.0, we have view templates with the new .html.erb extensions, but can also have .css.erb files.

does this mean i can put my css files inside my view templates like screen.css.erb or have i got the wrong end of the stick,

appreciate anyones answer on this,

---

<div class="post-metadata">

**Author:** ![radar](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/radar/32/604_2.png) [@radar](https://discuss.rubyonrails.org/u/radar)\
**Post date:** [April 29, 2008, 2:53pm UTC](https://discuss.rubyonrails.org/t/css-erb-files/28719/2 "2008-04-29T14:53:23Z")

</div>

stylesheet files should live in public/stylesheets and should be linked to by using \<%= stylesheet\_link\_tag “name” %\> in the layout of your site, inside a tag.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 29, 2008, 2:58pm UTC](https://discuss.rubyonrails.org/t/css-erb-files/28719/3 "2008-04-29T14:58:22Z")

</div>

i haven't used it yet, but i think that it's more about using erb code within your css file, which would allow to give them some nice things like user selectable color sets

.menu { &nbsp;&nbsp;color: \<%= @user.settings.text\_color; %\> &nbsp;&nbsp;background: \<%= @user.settings.bg\_color; %\>; }

hmm, i can think about a lot of stuff to do with it if it works that way.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 29, 2008, 3:22pm UTC](https://discuss.rubyonrails.org/t/css-erb-files/28719/4 "2008-04-29T15:22:21Z")

</div>

yep, Thorsten, would be pretty cool to have dynamic css files, don't think it works this way just confused by the extension.

maybe it's similar to haml?

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 29, 2008, 4:27pm UTC](https://discuss.rubyonrails.org/t/css-erb-files/28719/5 "2008-04-29T16:27:34Z")

</div>

Maybe you could store the user's color selections in a sort of "user preferences" model (which is what I've done with other user info).

I track the user's preferred "page length" (rows per page in an index view), "sort order" per model (saves their current sort columns and order when they logout so its the same when they come back).

I was just thinking about colors the other day - one co-worker doesn't see certain blue hues - "What highlight?" he asks...

Perhaps a "standard" stylesheet with my colors, then a stylesheet M-V-C that can maintain a css file per user, and some simple file selection logic in the main layout. Hmm...

Oh, and kuler.adobe.com is a great source for manufacturing/finding color schemes...

---

<div class="post-metadata">

**Author:** ![AndyV](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AndyV](https://discuss.rubyonrails.org/u/AndyV)\
**Post date:** [April 30, 2008, 1:39am UTC](https://discuss.rubyonrails.org/t/css-erb-files/28719/6 "2008-04-30T01:39:50Z")

</div>

You can dynamically link a css file (contra Radar ^^^) by using yield and content\_for

In the layout:

\<head\> ... \<%= yield :head %\> \</head\>

In the \*.html.erb \<% content\_for :head do %\> \<% stylesheet\_link\_tag :page\_specific\_styles \<% end %\>

Of course, if you \_needed\_ page specific, dynamic css you could put a style tag inside your content\_for :head.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 2, 2008, 7:33pm UTC](https://discuss.rubyonrails.org/t/css-erb-files/28719/7 "2008-05-02T19:33:59Z")

</div>

John Griffiths wrote:

> yep, Thorsten, would be pretty cool to have dynamic css files, don't think it works this way just confused by the extension.
> 
> maybe it's similar to haml?

You just have to think about how we normally find stylesheets, namely we link to a file located at "/stylesheets/blah.css"

normally this looks for a static file in "/public/stylesheets/blah.css"

but try adding a controller called Stylesheets.

now rails routing will look for a method called "blah" on the StylesheetsController.

try it, tweak it, cache it... boom

proper dynamic css.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 6, 2008, 1:26pm UTC](https://discuss.rubyonrails.org/t/css-erb-files/28719/8 "2008-05-06T13:26:48Z")

</div>

thanks, i'll have a bash and see how it goes.

appreciate this,

John.
