PDA

View Full Version : Embed inline Ruby & HTML?


travisbell
07-06-2008, 05:33 PM
Hey guys,

I am currently using eruby + Apache to use embedded Ruby like so:

This text is <% a = 100; puts "#{a}% Live!" %>

This is NOT a Rails site, just HTML with inline Ruby. I found out about it while reading through the Pragmatic Programmers guide here, http://www.ruby-doc.org/docs/ProgrammingRuby/html/web.html

For now, I am using LiteSpeed to serve the Apache pages via the LiteSpeed Web API but it would be way better if I could process the Ruby natively through LiteSpeed.

Is there a way I can get this done?

mistwang
07-06-2008, 07:11 PM
eRuby is CGI written in C, should be able to used together with LiteSpeed.

travisbell
07-06-2008, 07:18 PM
eRuby is CGI written in C, should be able to used together with LiteSpeed.

Yeah, I agree but couldn't get the MIME settings to work right in LS.

How can I go about adding the following MIME lines to LiteSpeed to make it work?

AddType application/x-httpd-eruby .rhtml
Action application/x-httpd-eruby /cgi-bin/eruby

Adding the AddType is easy but about about the Action?

mistwang
07-06-2008, 07:30 PM
No need to use those configuration. try rewrite rule

RewriteRule (.*\.rhtml)$ /cgi-bin/eruby/$1

This should pass the rhtml file as PATH_TRANSLATED to eruby CGI. give it a try.

travisbell
07-06-2008, 08:16 PM
I disabled the Apache proxy and put that .htaccess in. Now LiteSpeed just wants to download the file instead of parsing it or throwing an error.

Should I still put a MIME type in to recognize the .rhtml?

mistwang
07-07-2008, 12:52 PM
I tried the rewrite rule and it works.

Looks like your rewrite rule has not been configured properly. the request was not rewritten to /cgi-bin/eruby

travisbell
07-19-2008, 09:05 PM
My .htaccess looks like the following:


Options +Indexes

RewriteEngine On
RewriteRule (.*\.rhtml)$ /cgi-bin/eruby/$1


I have the .htaccess configured like so:

http://img.skitch.com/20080720-p8ggg65ehr4c59m11c1e6n9te5.preview.jpg (http://skitch.com/travisbell/tjjy/ijabber-htaccess)
Click for full size (http://skitch.com/travisbell/tjjy/ijabber-htaccess) - Uploaded with plasq (http://plasq.com)'s Skitch (http://skitch.com)

Now what happens is I get a "500 Internal Server Error" with the following error in my logs:


[124.170.97.88:65109-6#iJabber] Maximum number of redirect reached.


Any ideas why this isn't working?

mistwang
07-19-2008, 09:32 PM
You need to turn off rewrite in /cgi-bin/ directory. or test if the URL has been rewritten or not.

travisbell
07-19-2008, 10:52 PM
Got a little farther...

Disabled rewrite in /cgi-bin and now I get the following error in my logs:


[124.170.97.88:49646-0#iJabber] URI '/cgi-bin/eruby/register-gateway.rhtml' refers to a static file with PATH_INFO [/register-gateway.rhtml].

mistwang
07-20-2008, 06:57 AM
You need to add a CGI context for "/cgi-bin/".

travisbell
07-20-2008, 08:46 PM
You need to add a CGI context for "/cgi-bin/".

Yup, that did it. Thanks for your help with this :D