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)
views:
17answers:
2
+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
2010-06-24 05:45:12
For urls, you can access the params hash like so params[:param_name]
rmk
2010-06-24 05:52:59
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.
動靜能量
2010-06-24 06:08:35