Embed inline Ruby & HTML?

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

  1. travisbell

    travisbell New Member

    Hey guys,

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

    Code:
    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 New 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?

    Code:
    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 New 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 New Member

    My .htaccess looks like the following:

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

    [​IMG]
    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:

    Code:
    [124.170.97.88:65109-6#iJabber] 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 New Member

    Got a little farther...

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

    Code:
    [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].
    
  10. mistwang

    mistwang LiteSpeed Staff

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

    travisbell New Member

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

Share This Page