[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

abc-

3/15/2008 11:15:00 AM

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.s... =-

2 Answers

Eleanor McHugh

3/15/2008 11:46:00 AM

0

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:

<snip />

> 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-b... 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



B. Randy

6/12/2008 1:21:00 PM

0

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-b... 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
>
--
Posted via http://www.ruby-....