Best way to use ERb in a JavaScript file?

I am currently naming my JavaScript files with the extension .rhtml just
to be able of using ERb in them (“If the template file has a +.rhtml+
extension then it uses a mixture of ERb (included in Ruby) and HTML”,
Peak Obsession ). Does anybody
know of a better way?
I looked at RJS, but it doesn’t seem the right solution here.

xavi

Xavi C. wrote:

I am currently naming my JavaScript files with the extension .rhtml just
to be able of using ERb in them (“If the template file has a +.rhtml+
extension then it uses a mixture of ERb (included in Ruby) and HTML”,
Peak Obsession ). Does anybody
know of a better way?
I looked at RJS, but it doesn’t seem the right solution here.

Not sure why you wouldn’t use RJS, but I saw a blog posting about
setting up a route and controller to to use ERb on .rcss files. The
same technique should work for you:

http://blog.hasmanythrough.com/articles/2006/03/23/dirt-simple-rcss-templates


Devin Ben-Hur 503/860-4114 mailto:[email protected]

You may not have noticed, but we live in one of the safest,
most peaceful, times in human history. In the US, the three
leading causes of death are: killing yourself, killing yourself,
and killing yourself http://tinyurl.com/msxhq.


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.4/424 - Release Date:
8/21/2006

Devin Ben-Hur wrote:

Not sure why you wouldn’t use RJS, but I saw a blog posting about
setting up a route and controller to to use ERb on .rcss files. The
same technique should work for you:

http://blog.hasmanythrough.com/articles/2006/03/23/dirt-simple-rcss-templates

My JavasScript file is for the most part static, and I think that if use
RJS I would have to write lots of lines like the one below, wouldn’t I?

page << ‘rawJavaScript();’

On the other hand, thanks for the link! Yes, that should work, although
after seeing what has to be done, I think I will continue using the
.rhtml extension.

xavi