Forum: Ruby Process POST data

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
258b0d1886b55b90ef339c1caf69a41b?d=identicon&s=25 Alin Popa (chucky)
on 2007-01-26 22:30
Hi to all,

Recently, I had one little problem regarding Ruby and Processing POST
requests from a HTML form.
I know that there is Webrick for Servlets and stuff, but I want to know,
there is possible to process POST/GET requests with basic net/http and
mod_ruby?

I have one ruby script that receive some data from one html page
POST/GET.
I want to display or use in other scope these parameters.
How can this be done ?

Thanks in advance.

Alin.
88e98c5398a3b4af4d0eaefacf69f8b7?d=identicon&s=25 Parragh Szabolcs (Guest)
on 2007-01-27 10:31
(Received via mailing list)
Alin Popa írta:
> I have one ruby script that receive some data from one html page
> POST/GET.
>
The easy way is to make a new CGI object in your script, that mod_ruby
runs, and ask for the parameters, POST-ed ones will be there, too.

E.g: in your ruby script file:

require 'cgi'

cgi = CGI.new
get_data(cgi)

def get_data(cgi)
  user = User.new
  User.name = cgi['name']
  User.age = cgi['age']
  ...
end
258b0d1886b55b90ef339c1caf69a41b?d=identicon&s=25 Alin Popa (chucky)
on 2007-01-27 12:58
Parragh Szabolcs wrote:
> Alin Popa �rta:
>> I have one ruby script that receive some data from one html page
>> POST/GET.
>>
> The easy way is to make a new CGI object in your script, that mod_ruby
> runs, and ask for the parameters, POST-ed ones will be there, too.
>
> E.g: in your ruby script file:
>
> require 'cgi'
>
> cgi = CGI.new
> get_data(cgi)
>
> def get_data(cgi)
>   user = User.new
>   User.name = cgi['name']
>   User.age = cgi['age']
>   ...
> end

Thanks Parragh,

Great help, with one small notice:

I used exactly your example, BUT I called the method get_data, after
declaration of it, because if I call it before, I'll get 500 Internal
Server Error.

Best regards,

Alin
This topic is locked and can not be replied to.