Forms

Hi. I'm new here, and new at programming Ruby. I have a question about
it though.

Is there a possible way to write forms in HTML, and then read them using
a Ruby equivalent to the PHP $_GET or $_POST on the page where the
method points?

···

--
Posted via http://www.ruby-forum.com/.

Harry Sa wrote:

Is there a possible way to write forms in HTML, and then read them using
a Ruby equivalent to the PHP $_GET or $_POST on the page where the
method points?
  
Check out Ruby's CGI library at http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html\.

HTH,
Jim

Yes, there is.

On your ruby application endpoint, you would need something like this:

require "cgi"
cgi = CGI.new
value = cgi['field_name'] # <== value string for 'field_name'

And do all sorts of Ruby operations:

# if not 'field_name' included, then return "".
fields = cgi.keys # <== array of field names

# returns true if form has 'field_name'
cgi.has_key?('field_name')
cgi.has_key?('field_name')
cgi.include?('field_name')

On the same scoop of concept you were viewing it, cgi['field_name'] it's
kind of the same as PHP's $_REQUEST['field_name'].

Actually, I extracted that sample above from the cgi module documentation
somebody else already pointed to you.

Enjoy,
D.

···

On Feb 11, 2008 1:17 PM, Harry Sa <rule.brittania@hotmail.co.uk> wrote:

Hi. I'm new here, and new at programming Ruby. I have a question about
it though.

Is there a possible way to write forms in HTML, and then read them using
a Ruby equivalent to the PHP $_GET or $_POST on the page where the
method points?
--
Posted via http://www.ruby-forum.com/\.

--
David Moreno - http://www.damog.net/
Yes, you can.