[Rails] Using register_template_handler to serve CSS files (Making ActionView handle .css as .rhtml)

Iván Vega Rivera ivanvega at gmail.com
Sun Jan 22 02:19:23 GMT 2006


Hi,

I wanted to be able to use some Rails code inside CSS files, so I set up 
a controller (StylesController) to serve CSS files that reside inside 
the controller's view folder when the browser requests /stylesheets/:action

So in the controller I just define empty actions with the names I want 
my style sheets in (ie: def cooleffects end - that would respond to 
/stylesheets/cooleffects).

And in views/styles I have cooleffects.css

Then, I tried the following (both inside the controller, and in a 
plugin's init.rb):

ActionView::Base.register_template_handler 'css', ActionView::Base

Which doesn't seem to have any effect, because Rails throws an error on 
the CSS file (no matter if I comment the line above):

|No rhtml, rxml, or delegate template found for |<contents of the CSS file>

So, how can I make ActionView handle CSS files as if they were RHTML files?

Thanks!

Ivan V.



More information about the Rails mailing list