tags:

views:

17

answers:

2

In Ruby (running on a web server as a .cgi), how do you print out the URL params and Server environment variables, preferable without using any package? (by the rawest form)

+1  A: 

These are passed to the Ruby interpreter itself via env variables; so you'll probably want to use the cgi package to get at them. E.g.:

require 'cgi'
print "Content-type: text/html\n"

print CGI.new.params; 

For more, view the CGI documentation at http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html

(BTW, mod-ruby that apache uses is flawed; you should try out Mongrel and Rack if you wanna go your own way as opposed to using Rails or Merb.)

aharon
For urls, you can access the params hash like so params[:param_name]
rmk
A: 

thanks for the answer. I also found something in the cgi package code that the variable

ENV

can be used to show all server variables. It contains environment variables even if running ruby or irb in a shell or command prompt.

動靜能量