views:

53

answers:

4

Hello ,

I am having an rails application,in which I need a css file in such a way that its property can be changed by ruby code. ex. background_color :<%= ruby code that return background color %>

So a user can set its css property and will be applicable to only that user like a theme.

Thanks!

A: 

Check out this tutorial on using the SASS engine to dynamically change CSS.

davidcelis
+2  A: 

Also, take a look at http://lesscss.org/

Matthew
A: 

Check out this screencast which explains how to set up dynamic CSS files using ERB (the Rails templating system) http://nubyonrails.com/system/images/css-erb-small.mov

David Burrows
A: 

If you just need something simple, then you could do in your layout:

<head>
....
<% unless current_user.theme.nil? %>
<style>
body{
  background:<%= current_user.theme.background_color%>;
}
</style>
</head>
<% end %>

If you're starting a new project, SASS is the way to go, and probably is the way to go if you have sufficient time. If just a couple of entries, it might not be bad to do it in the HTML.

Note: I feel a little dirty about this, but it'll work.

Jesse Wolgamott