# Dynamic CSS Generation

**URL:** <https://discuss.rubyonrails.org/t/dynamic-css-generation/19089>\
**Category:** rubyonrails-talk\
**Created:** [October 10, 2007, 12:09am UTC](https://discuss.rubyonrails.org/t/dynamic-css-generation/19089 "2007-10-10T00:09:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![GT1](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@GT1](https://discuss.rubyonrails.org/u/GT1)\
**Post date:** [October 10, 2007, 12:09am UTC](https://discuss.rubyonrails.org/t/dynamic-css-generation/19089/1 "2007-10-10T00:09:04Z")

</div>

Hi Cory,

I would put the style name to an instance variable.

def define\_style &nbsp;&nbsp;if request.user\_agent.includes("some\_cryptic\_ie\_string") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@style = "style1" &nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@style = "style2" &nbsp;&nbsp;end end

In your view (most likely in your layout), add following line. You need to put style1.css and style2.css in public/css.

\<%= stylesheet\_link\_tag @style %\>

Also, do not forget to add before filter. class YourController \< ApplicationController before\_filter :define\_style

This way, define\_style is called every time the controller is processed.

Cheers, Glen
