# .css.erb files?

**URL:** <https://www.ruby-forum.com/t/css-erb-files/136173>\
**Category:** Rails\
**Created:** [April 29, 2008, 4:42pm UTC](https://www.ruby-forum.com/t/css-erb-files/136173 "2008-04-29T16:42:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [April 29, 2008, 4:42pm UTC](https://www.ruby-forum.com/t/css-erb-files/136173/1 "2008-04-29T16: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:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [April 29, 2008, 4:54pm UTC](https://www.ruby-forum.com/t/css-erb-files/136173/2 "2008-04-29T16:54:31Z")

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

On Wed, Apr 30, 2008 at 12:12 AM, John G. \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> >

–  
Ryan B.  
[http://www.frozenplague.net](http://www.frozenplague.net)  
Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [April 29, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/css-erb-files/136173/3 "2008-04-29T16: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 {  
color: \<%= @user.settings.text\_color; %\>  
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:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [April 29, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/css-erb-files/136173/4 "2008-04-29T18: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](http://kuler.adobe.com) is a great source for manufacturing/finding  
color schemes…

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [April 29, 2008, 5:22pm UTC](https://www.ruby-forum.com/t/css-erb-files/136173/5 "2008-04-29T17: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:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [April 30, 2008, 3:40am UTC](https://www.ruby-forum.com/t/css-erb-files/136173/6 "2008-04-30T03:40:51Z")

</div>

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

In the layout:

... \<%= yield :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.

On Apr 29, 12:27 pm, Ar Chron [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [May 2, 2008, 9:33pm UTC](https://www.ruby-forum.com/t/css-erb-files/136173/7 "2008-05-02T21:33:59Z")

</div>

John G. 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:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [May 6, 2008, 3:26pm UTC](https://www.ruby-forum.com/t/css-erb-files/136173/8 "2008-05-06T15:26:48Z")

</div>

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

appreciate this,

John.
