# Webrick

**URL:** <https://www.ruby-forum.com/t/webrick/132015>\
**Category:** Ruby\
**Created:** [March 15, 2008, 12:20pm UTC](https://www.ruby-forum.com/t/webrick/132015 "2008-03-15T12:20:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 15, 2008, 12:20pm UTC](https://www.ruby-forum.com/t/webrick/132015/1 "2008-03-15T12:20:58Z")

</div>

Hi,

i’m new to ruby and tried some code to get a small application.  
I used Webrick to get a http server:

require ‘webrick’  
include WEBrick  
s = HTTPServer.new(:Port =\> 8000)

# Add a mime type for \*.rhtml files

HTTPUtils::DefaultMimeTypes.store(‘rhtml’, ‘text/html’)

# Required for CGI on Windows; unnecessary on Unix/Linux

s.config.store( :CGIInterpreter, “#{HTTPServlet::CGIHandler::Ruby}”)

# Mount servlets

s.mount(‘/test’, HTTPServlet::FileHandler, ‘/’)

# Trap signals so as to shutdown cleanly.

[‘TERM’, ‘INT’].each do |signal|  
trap(signal){ s.shutdown }  
end

# Start the server and block on input.

s.start

and i created an rhtml file:

 Ruby Test 
## Test
 \<% require 'mysql' %\> \<% my = Mysql::new("localhost", "root", "", "books\_development") %\> \<% res = my.query("select ID,Name from books Limit 10") %\> \<% res.each { |i| puts "" } %\> 

| #{i} |

Now the problem is that i can see the html in my browser but the result  
of embedded Ruby code only in my Konsole. Could anyone give me the right  
direction.

Thanks in advance  
dirk

--------------= Posted using GrabIt =----------------  
------= Binary Usenet downloading made easy =---------  
-= Get GrabIt for free from [http://www.shemes.com/](http://www.shemes.com/) =-

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 15, 2008, 12:46pm UTC](https://www.ruby-forum.com/t/webrick/132015/2 "2008-03-15T12:46:48Z")

</div>

On 15 Mar 2008, at 11:20, abc- wrote:

> i’m new to ruby and tried some code to get a small application.  
> I used Webrick to get a http server:

> Now the problem is that i can see the html in my browser but the  
> result of embedded Ruby code only in my Konsole. Could anyone give  
> me the right direction.

Before serving the rhtml file to your web client you need to run ERb  
on it and capture the result, then serve it using a different method  
than HTTP::Servlet.

I can’t remember the details off-hand but if you look at my Camping  
presentation at [http://slides.games-with-brains.net/](http://slides.games-with-brains.net/) you’ll find some  
simple examples of rolling WEBrick servers and integrating ERb is  
fairly simple. I usually just add it into the String class as a handy  
instance method:

class String  
def apply\_erb  
ERB.new(self).result  
end  
end

so when generating the output for the server you’d have a line roughly  
like:

my\_content.apply\_erb

where my\_content is the variable holding the rhtml page text, or a  
method that produces it.

Ellie

## Eleanor McHugh Games With Brains

raise ArgumentError unless @reality.responds\_to? :reason

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 12, 2008, 3:21pm UTC](https://www.ruby-forum.com/t/webrick/132015/3 "2008-06-12T15:21:39Z")

</div>

Hello Ellie,

I use WEBrick and Erb too and I want get all data (a array whith 3  
columns) from a big FORM, maybe by the POST method, but I’ve no idea how  
to make this ☹

You make a reference to yours slides. I’ve tried many times to “join”  
the group and to download the file without success. And the delay of  
communication is long, long, so long !

Have you an other place to get your presentation, or the solution could  
you help me to find the right solution ? 🙂

Thanks.

Eleanor McHugh wrote:

> On 15 Mar 2008, at 11:20, abc- wrote:
> 
> > i’m new to ruby and tried some code to get a small application.  
> > I used Webrick to get a http server:
> 
> I can’t remember the details off-hand but if you look at my Camping  
> presentation at [http://slides.games-with-brains.net/](http://slides.games-with-brains.net/) you’ll find some  
> simple examples of rolling WEBrick servers and integrating ERb is  
> fairly simple.
> 
> I usually just add it into the String class as a handy  
> instance method:
> 
> class String  
> def apply\_erb  
> ERB.new(self).result  
> end  
> end
> 
> so when generating the output for the server you’d have a line roughly  
> like:
> 
> my\_content.apply\_erb
> 
> where my\_content is the variable holding the rhtml page text, or a  
> method that produces it.
> 
> Ellie
