[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

ruby-web and trapping errors

ivan.pavlov

1/17/2006 5:03:00 PM

I am using ruby-web to create a simple web application. Basically I
have some code, I process submitted forms and then I do

Web::open do
puts html
end

If an error occurs in the code I get : Internal Server Error in the
browser and no information whatsoever about the error.

My question is - can I make the exact error appear in the browser, so I
can fix it easily? I can run my code in console and then I see the
error but if I have user-submitted data before the error occured it
becomes difficult...

3 Answers

ivan.pavlov

1/17/2006 5:21:00 PM

0

Oops, this was stupid question - I found the answer myself.

begin
# code code code
rescue Exception => detail
Web::open do
puts detail.backtrace.join('<br>')
puts detail.to_s
end
end

patsplat

1/21/2006 12:58:00 AM

0

This is the main reason ruby-web provides a 'web-aware' interpreter.
There are certain types of errors that Web::open can't catch,
especially the dreaded "syntax error".

If you use the ruby-web interpreter, it will output cgi headers, plus
the Web::open block is not needed:

#!/usr/bin/ruby-web

....
puts html

This will catch the error and display to the browser. The cgi
interpreter works on Windows and Unix platforms, with fastcgi support
in linux if you installed the fcgi libraries. There are also ruby-web
handers for ModRuby which provide the same support. All the gory
details are at:

http://ruby-web.org/manual/in...

Thanks for trying it out!

Cheers,

Patrick

ivan.pavlov

1/21/2006 7:27:00 AM

0

Patrick, thanks for the pointer to #!/usr/bin/ruby-web , I missed this
during the installation. Well, I guess I missed all the install
instructions.

I am very new to Ruby and am just exploring different things. Rails is
far too much for my needs and I found ruby-web does exactly what I
want. I probably use like 1% of its capabilities, because all I really
need are the data submitted by the user, once I have them, all the
program flow goes through various classes which in the end return a
string cotaining the whole HTML of the page. All the logic is in the
classes and I do not need to output anything piece by piece. So, in the
end I have a string which I pass to a single Web::open block and I'm
done.

I am using templates of course; having programmed in PHP for several
years I hate plain HTML in my code, so I took probably the worse
approach - wrote a small template engine myself, for reasons described
below.

In the end, I have to say I'm beginning to like Ruby. Code is shorter
than PHP and more elegant, which does not necessarily mean it takes
less time to write but sometimes it does. My only frustration is the
lack of good documentation for the external libraries I download from
rubyforge. Most people seem to think that a hastily prepared rdoc is
enough, and that examples are not really necessary because the user has
like 5 years of Ruby experience and understatnds everything just by
looking at a method name. I am not speaking here about the core classes
and methods which are indeed very well-documented.

I know that writing documentation is a pain. But this can really speed
up adoption of the language. Good, working examlpes of something
meaningful are the best documentation.


p.s. Patrick, this entry is in no way connected to ruby-web, I got
frustrated over some other libraries, like rexml.