Forum: Ruby on Rails Using register_template_handler to serve CSS files (Making A

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C5380b957ff8ce5cb14cf2282ffeb720?d=identicon&s=25 Iván Vega Rivera (Guest)
on 2006-01-22 03:18
(Received via mailing list)

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

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

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


Ivan V.
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-01-22 13:46
(Received via mailing list)
    >  I wanted to be able to use some Rails code inside CSS files,

Do you know RCSS?
It lets you use Erb inside css stylesheets.

Note: I've experienced some problems when using RCSS on a shared server
(Dreamhost). I wonder if it's related to RCSS resource need:it has to
translate the RCSS file into a CSS one. What happened is that the page
would sometimes render without any styling, as when you remove all the
stylesheed. Refreshing the page would have display correctly.

C5380b957ff8ce5cb14cf2282ffeb720?d=identicon&s=25 Iván Vega Rivera (Guest)
on 2006-01-22 16:45
(Received via mailing list)
Thanks Alain, it looks very interesting, specially the server-side
constants, which are something that I was looking to implement using
plain old  erb code.

However, since you mention some problems with it, I'll just keep an eye
on it for future usage. Right now, I went with this:

        tpl = ''"#{RAILS_ROOT}/app/views/styles/#{params['cssfile']}")
do |css|
            while line = css.gets
                tpl += line
        render_template tpl

Ivan V.

Alain Ravet
escribió:> Iván
This topic is locked and can not be replied to.