Webrick

A

abc-

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:

<html>
<head>
<title>Ruby Test</title>
</head>
<body>
<h2>Test</h2>

<form>
<% require 'mysql' %>
<% my = Mysql::new("localhost", "root", "", "books_development") %>
<% res = my.query("select ID,Name from books Limit 10") %>
<table>
<% res.each { |i| puts "<tr><td> #{i} </td></tr>" } %>
</table>
</form>
</body>
</html>

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/ =-
 
E

Eleanor McHugh

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/ 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
 
B

B. Randy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top