tags:

views:

12

answers:

1

I'm currently hosted on a Mediatemple gridserver. I'm writing a site to teach myself Ruby - straight ruby, no rails. I've run into a few errors that appear to be a result of nested tags. For example:

eruby requires <% %> tags around ruby code. If I try to use erb templating I'm stuffed -

<%
template = ERB.new <<-EOF
  The value of x is: <%= x %>
EOF
%>

This obviously won't work because of the nested <% %> tags. I think I'm running into a similar issue with the CGI class. Is there a way to alter the tags used for either erb or eruby? Or is there an easy way around this I'm totally missing?

A: 

You probably don't want to use both erb and eruby. You should make the eruby (or erb) from a ruby cgi script.

require "cgi"
require "erb"

x = 42
template = ERB.new <<-EOF
  The value of x is <%= x %>
EOF

cgi = CGI.new
cgi.out { template.result }
cam
That's the problem. Apparently the server setup means the only way to get Ruby to execute is via eruby. To get the code you supplied to run, it would need to all be nested within <% %> tags, which would then break the code due to the nested <% %> tags.
sketchy
hmm, that's a pretty poor setup. i would advise switching hosts if possible.
cam
ok, i was skeptical about your host only supporting erb. I'm pretty sure that is not the case. You could run cgi scripts in cgi-bin, or follow the advice in this article to run it in your documentroot:http://kb.mediatemple.net/questions/30/Running+scripts+outside+of+the+cgi-bin
cam