Embed inline Ruby & HTML?

Discussion in 'Ruby/Rails' started by travisbell, Jul 7, 2008.

  1. travisbell

    travisbell Well-Known Member

    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?
  2. mistwang

    mistwang LiteSpeed Staff

    eRuby is CGI written in C, should be able to used together with LiteSpeed.
  3. travisbell

    travisbell Well-Known Member

    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?
  4. mistwang

    mistwang LiteSpeed Staff

    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.
  5. travisbell

    travisbell Well-Known Member

    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?
  6. mistwang

    mistwang LiteSpeed Staff

    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
  7. travisbell

    travisbell Well-Known Member

    My .htaccess looks like the following:

    Options +Indexes
    RewriteEngine On
    RewriteRule (.*\.rhtml)$ /cgi-bin/eruby/$1
    I have the .htaccess configured like so:

    Click for full size - Uploaded with plasq's Skitch

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

    [] Maximum number of redirect reached.
    Any ideas why this isn't working?
  8. mistwang

    mistwang LiteSpeed Staff

    You need to turn off rewrite in /cgi-bin/ directory. or test if the URL has been rewritten or not.
  9. travisbell

    travisbell Well-Known Member

    Got a little farther...

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

    [] URI '/cgi-bin/eruby/register-gateway.rhtml' refers to a static file with PATH_INFO [/register-gateway.rhtml].
  10. mistwang

    mistwang LiteSpeed Staff

    You need to add a CGI context for "/cgi-bin/".
  11. travisbell

    travisbell Well-Known Member

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

Share This Page