Take the 2-minute tour ×

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)

share|improve this question
add comment

2 Answers

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.)

share|improve this answer
For urls, you can access the params hash like so params[:param_name] –  rmk Jun 24 '10 at 5:52
add comment
up vote 1 down vote accepted

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


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

share|improve this answer
add comment

Your Answer


