nonopolarity
nonopolarity

Reputation: 150986

In Ruby, how do you print out the URL params and Server environment variables?

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)

Upvotes: 0

Views: 1129

Answers (2)

nonopolarity
nonopolarity

Reputation: 150986

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.

Upvotes: 1

Aaron Yodaiken
Aaron Yodaiken

Reputation: 19551

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

Upvotes: 1

Related Questions