[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Problem with WEBRick and eruby

vendemotos

2/3/2007 8:56:00 AM

Hi,

I am just starting in both ruby and web development so maybe the
following pieces of code seem a sin for most of you.

I am writing a HTML form in a rhtml file and pass the parameters to
antoher rhtml with embebed ruby.

The HTTP server is built as follows:

-----------------

require 'webrick'
include WEBrick

def start_webrick(config = {})
config.update(:Port => 8080)
config.update(:MimeTypes => {'rhtml' => 'text/html'})
server = HTTPServer.new(config)
yield server if block_given?
['INT', 'TERM'].each {|signal|
trap(signal) {server.shutdown}
}
ruby_dir = File.expand_path('/www')
server.mount("/www", HTTPServlet::ERBHandler, ruby_dir)
server.start
end

start_webrick(:DocumentRoot => '/www')

-----------

the index.htrml is like follows

-----------

<HTML>
<FORM action="response.rhtml" method="POST">
METAR: <INPUT type="text" name="metar" size=80><BR>
<INPUT type="submit" value="Process">
</FORM>
</HTML>

----------


And finally the response.rhtml is

--------
<HTML>
<%
require 'cgi'

cgi = CGI.new

#Rest of code
%>
</HTML>
--------

The webrick server shows the following info while the loading of
response.rhtml simply freezes

----------
[2007-02-03 09:48:15] INFO WEBrick 1.3.1
[2007-02-03 09:48:15] INFO ruby 1.8.5 (2006-08-25) [i386-mswin32]
[2007-02-03 09:48:15] INFO WEBrick::HTTPServer#start: pid=1372
port=8080
nicalejo - - [03/Feb/2007:09:48:29 Romance Standard Time] "GET / HTTP/
1.1" 200 1
93
- -> /
[2007-02-03 09:48:43] ERROR `/response.rhtml' not found.
nicalejo - - [03/Feb/2007:09:48:43 Romance Standard Time] "POST /
response.rhtml
HTTP/1.1" 404 284
http://localhost:8080 -> /response.rhtml
(offline mode: enter name=value pairs on standard input)
-----------

Why this offline message? Any suggestion?

Thanks in advance to the rubyists

2 Answers

Jano Svitok

2/3/2007 9:27:00 AM

0

On 2/3/07, vendemotos@gmail.com <vendemotos@gmail.com> wrote:
> Hi,
>
> I am just starting in both ruby and web development so maybe the
> following pieces of code seem a sin for most of you.
>
> I am writing a HTML form in a rhtml file and pass the parameters to
> antoher rhtml with embebed ruby.
>
> The HTTP server is built as follows:
>
> -----------------
>
> require 'webrick'
> include WEBrick
>
> def start_webrick(config = {})
> config.update(:Port => 8080)
> config.update(:MimeTypes => {'rhtml' => 'text/html'})
> server = HTTPServer.new(config)
> yield server if block_given?
> ['INT', 'TERM'].each {|signal|
> trap(signal) {server.shutdown}
> }
> ruby_dir = File.expand_path('/www')
> server.mount("/www", HTTPServlet::ERBHandler, ruby_dir)
> server.start
> end
>
> start_webrick(:DocumentRoot => '/www')
>
> -----------
>
> the index.htrml is like follows
>
> -----------
>
> <HTML>
> <FORM action="response.rhtml" method="POST">
> METAR: <INPUT type="text" name="metar" size=80><BR>
> <INPUT type="submit" value="Process">
> </FORM>
> </HTML>
>
> ----------
>
>
> And finally the response.rhtml is
>
> --------
> <HTML>
> <%
> require 'cgi'
>
> cgi = CGI.new
>
> #Rest of code
> %>
> </HTML>
> --------
>
> The webrick server shows the following info while the loading of
> response.rhtml simply freezes
>
> ----------
> [2007-02-03 09:48:15] INFO WEBrick 1.3.1
> [2007-02-03 09:48:15] INFO ruby 1.8.5 (2006-08-25) [i386-mswin32]
> [2007-02-03 09:48:15] INFO WEBrick::HTTPServer#start: pid=1372
> port=8080
> nicalejo - - [03/Feb/2007:09:48:29 Romance Standard Time] "GET / HTTP/
> 1.1" 200 1
> 93
> - -> /
> [2007-02-03 09:48:43] ERROR `/response.rhtml' not found.
> nicalejo - - [03/Feb/2007:09:48:43 Romance Standard Time] "POST /
> response.rhtml
> HTTP/1.1" 404 284
> http://localhost:8080 -> /response.rhtml
> (offline mode: enter name=value pairs on standard input)
> -----------
>
> Why this offline message? Any suggestion?
>
> Thanks in advance to the rubyists

Hi,
CGI expects data on stdin (see the message). The problem is that
webrick doesn't pass it to ERB pages as such. Look at ERB handler how
the vars are actually sent (I suppose there would be some @request or
similar).

vendemotos

2/3/2007 11:22:00 AM

0



Sorry, but I did not find the way WEBrick send the vars of the uri