tags:

views:

531

answers:

1

Hello,

I'm trying to get the query_string from a Ruby file. For example;

http://localhost/rubyfile.rb?hello=world

I would like to be able to ask what's hello and for it to print "world", but for the life of me I cannot find the correct syntax/way to do it anywhere. Even the Ruby documentation seems dazed.

#!/program files (x86)/ruby/bin/ruby

require 'cgi'
cgi_request = CGI::new("html4")

This simply starts a new CGI spawn when the file is run, but how do I find the query_string?

puts cgi.params[query_string]

Doesn't seem to work-- I assume there is something i'm completly missing and im stupid but...

It should be simple, shouldn't it?

Thanks

+2  A: 

The following should work:

require "cgi"
cgi_request = CGI::new("html4")

puts "Content-Type: text/html; charset=UTF-8"
puts
puts cgi_request['hello']
puts cgi_request.query_string
puts cgi_request.params['hello']
Ionuț G. Stan
You, sir, and that's what you are; a sir, are a god among men.cgi_request['hello'] prints world,cgi_request.query_string prints the whole query string, hello=world,cgi_request.params['hello'] prints world like the first.You are my jesus.