Problem running Ruby ERB script on Apache Tomcat 6.0.13

Problem running Ruby ERB script on Apache Tomcat 6.0.13

am 17.10.2007 06:15:45 von RichardOnRails

Hi All,

http://www.hiveminds.co.uk/node/3189 showed how to run a stand-alone
(as opposed to running under Rails) ERB script. I couldn't make that
work.

I started Apache Tomcat 6.013 on Win2KSP2
I tested it with the address http://localhost:8080/ in Firefox 2 and
got the Apache Jakarta Project page.
I created IntroToERB.rb file as suggested by the HiveMinds site and as
shown below.
I gave Firefox the address file:///K:/_Projects/Ruby/_ERB/110-Intro/IntroToERB.rb
Instead of the executed ERB results, I got a listing of the file in
the browser.

Anybody got any ideas how I can get Tomcat to execute IntroToERB.rb
rather than list it?

Thanks in Advance,
Richard

IntroToERB.rb
==========
# IntroToERB.rb
# Directory: K:\_Projects\Ruby\_ERB\110-Intro
# Source: http://www.hiveminds.co.uk/node/3189

# We are going to use erubis for templating rather than ERB
require 'erb'

#CGI is needed for headers. Without it the the output may default to
plain text
require 'cgi'

# set a new object
cgi = CGI.new("html4")

# print header type
print cgi.header("type"=>"text/html")

# show usage of CGI HTML in the template
headline = cgi.h1 { "A page: " } + "\n" + cgi.hr

# read the template file. The name can be anything but we use "eruby"
to avoid confusion.
input = File.read('example1.eruby')

# mix the template (input from above) and this file to create the
eRuby object
eruby = ERB.new(input)

# Create some Ruby code that can be outputed to the template page
list = ['aaa', 'bbb', 'ccc','ddd','your name']
name = ' A list of items 2'

# Print the result of the two files.
puts eruby.result(binding())

# call this file in your browser

Re: Problem running Ruby ERB script on Apache Tomcat 6.0.13

am 17.10.2007 13:48:00 von RichardOnRails

On Oct 17, 12:15 am, RichardOnRails
wrote:
> Hi All,
>
> http://www.hiveminds.co.uk/node/3189showed how to run a stand-alone
> (as opposed to running under Rails) ERB script. I couldn't make that
> work.
>
> I started Apache Tomcat 6.013 on Win2KSP2
> I tested it with the address http://localhost:8080/ in Firefox 2 and
> got the Apache Jakarta Project page.
> I created IntroToERB.rb file as suggested by the HiveMinds site and as
> shown below.
> I gave Firefox the address file:///K:/_Projects/Ruby/_ERB/110-Intro/IntroToERB.rb
> Instead of the executed ERB results, I got a listing of the file in
> the browser.
>
> Anybody got any ideas how I can get Tomcat to execute IntroToERB.rb
> rather than list it?
>
> Thanks in Advance,
> Richard
>
> IntroToERB.rb
> ==========
> # IntroToERB.rb
> # Directory: K:\_Projects\Ruby\_ERB\110-Intro
> # Source:http://www.hiveminds.co.uk/node/3189
>
> # We are going to use erubis for templating rather than ERB
> require 'erb'
>
> #CGI is needed for headers. Without it the the output may default to
> plain text
> require 'cgi'
>
> # set a new object
> cgi = CGI.new("html4")
>
> # print header type
> print cgi.header("type"=>"text/html")
>
> # show usage of CGI HTML in the template
> headline = cgi.h1 { "A page: " } + "\n" + cgi.hr
>
> # read the template file. The name can be anything but we use "eruby"
> to avoid confusion.
> input = File.read('example1.eruby')
>
> # mix the template (input from above) and this file to create the
> eRuby object
> eruby = ERB.new(input)
>
> # Create some Ruby code that can be outputed to the template page
> list = ['aaa', 'bbb', 'ccc','ddd','your name']
> name = ' A list of items 2'
>
> # Print the result of the two files.
> puts eruby.result(binding())
>
> # call this file in your browser

Hi,

Forget my previous question. It's got too many complications.

I've simplified my question: I created a simpler test file:

HelloWorld.rb
==========
# file:///K:/_Projects/Ruby/_ERB/110-Intro/HelloWorld.rb
print "Hello World!\r\n"

When I open a Command window in WinXP/SP2,
and enter the command K:/_Projects/Ruby/_ERB/110-Intro/HelloWorld.rb,
I get (compliments of the Ruby Interpreter):
Hello World!

If I simply double-click the filename HelloWorld.rb in Windows
Explorer, I get a Command Window that opens and closes in a flash.
That happens compliments of the Ruby Interpreter, and the ".rb"
association set up in Windows Explorer.

My question is how can I get Apache-Tomcat to process HelloWorld.rb so
that Apache invokes the Ruby Interpreter for that file and dumps the
output into my default browser, Firefox?

As I mentioned in the previous post, I know Apache Tomcat is alive and
well because I tested it with the address http://localhost:8080/ in
Firefox 2 and got the Apache Jakarta Project page.

Any suggestions or links to a site that address this question would be
gratefully received.

Best wishes,
Richard