I am in the process of doing some web page authoring using eRuby.
My question is this-- how do I access the post/get information in URL
rewriting? I know in PHP you use something like
$_GET[“key”]
given the following URL: http://www.xyz.com/index.html?key=RUBYRULZ
Does eRuby have the equivalent?
···
Compare high-speed Internet plans, starting at $26.95.
https://broadband.msn.com (Prices may vary by service area.)
Rasputin1
(Rasputin)
17 November 2003 13:09
2
I am in the process of doing some web page authoring using eRuby.
My question is this-- how do I access the post/get information in URL
rewriting? I know in PHP you use something like
$_GET[“key”]
given the following URL: .xyz Domain Names | Join Generation XYZ
use CGI.rb for that kind of thing, it plays nicely with eruby.
···
–
The price of seeking to force our beliefs on others is that someday
they might force their beliefs on us.
– Mario Cuomo
Rasputin :: Jack of All Trades - Master of Nuns
require ‘cgi’
cgi = CGI.new
key = cgi[‘key’]
p key
[ "RUBYRULZ " ]
key.type
Array
cgi.query_string.split(“&”).each {|x| p x }
"RUBYRULZ "
#“rubyrulz”
-r.
Rasputin wrote:
···
I am in the process of doing some web page authoring using eRuby.
My question is this-- how do I access the post/get information in URL
rewriting? I know in PHP you use something like
$_GET[“key”]
given the following URL: .xyz Domain Names | Join Generation XYZ
use CGI.rb for that kind of thing, it plays nicely with eruby.
“Bermejo, Rodrigo” rodrigo.bermejo@ps.ge.com writes:
cgi.query_string.split(“&”).each {|x| p x }
"RUBYRULZ "
#“rubyrulz”
Actually, it’s:
irb(main):002:0> cgi.query_string.split(“&”).each {|x| p x }
“key=RUBYRULZ”
“key2=rubyrulz”
I’m sure you just meant that as an example of how to access the query
string directly, but FYI, it’s broken in other ways too-- modern
browsers are allowed to use ‘;’ to separate variables in a GET
request. In fact, I believe it is now the preferred form. Much
friendlier to do:
cgi.keys.each { |key| p cgi[key] }
anyway
-=Eric
···
–
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton.
Rasputin1
(Rasputin)
18 November 2003 14:07
5
.xyz Domain Names | Join Generation XYZ
require ‘cgi’
cgi = CGI.new
key = cgi[‘key’]
p key
[ "RUBYRULZ " ]
key.type
Array
cgi.query_string.split(“&”).each {|x| p x }
"RUBYRULZ "
#“rubyrulz”
See below for an rhtml file
Rasputin wrote:
I am in the process of doing some web page authoring using eRuby.
My question is this-- how do I access the post/get information in URL
rewriting? I know in PHP you use something like
given the following URL: .xyz Domain Names | Join Generation XYZ
For the sake of completeness, here’s a .rhtml example:
<% require ‘cgi’ # Require the CGI library
cgi = CGI.new() # New CGI object
key = cgi.params[‘key’]
%>Test
<% if key.empty? %>
Please enter the key:
<% else %>
the key is :<%= key %>
<% end %>
···
–
Radioactive cats have 18 half-lives.
Rasputin :: Jack of All Trades - Master of Nuns
Eric Schwartz wrote:
“Bermejo, Rodrigo” rodrigo.bermejo@ps.ge.com writes:
cgi.query_string.split(“&”).each {|x| p x }
"RUBYRULZ "
#“rubyrulz”
Actually, it’s:
irb(main):002:0> cgi.query_string.split(“&”).each {|x| p x }
“key=RUBYRULZ”
“key2=rubyrulz”
I’m sure you just meant that as an example of how to access the query
string directly,
Yeah a mistake…I’m not as cleaver as irb =)
but FYI, it’s broken in other ways too-- modern
browsers are allowed to use ‘;’ to separate variables in a GET
request.
Oh, I did know it …modern browsers like … ? …just to be aware of
In fact, I believe it is now the preferred form. Much
friendlier to do:
cgi.keys.each { |key| p cgi[key] }
Thanks
anyway
-=Eric
BTW, I really don’t understand why cgi[‘query’].class => Array ?
-Ronnie.
– “Bermejo, Rodrigo” rodrigo.bermejo@ps.ge.com writes: –
BTW, I really don’t understand why cgi[‘query’].class => Array ?
Because it is possible to specify more than one value for param either in
the URL in the case of a GET or in the header in the case of a POST.
For example, given the following form:
<html>
<body>
<form method="get">
What kinds of fruit do you like? <br />
<input type="checkbox" name="fruit" value="apples" /> Apples <br />
<input type="checkbox" name="fruit" value="oranges" /> Oranges <br />
<input type="checkbox" name="fruit" value="cherries"/> Cherries <br
/>
If you check Apples and Oranges, then press submit the following url will be
submitted:
http://myurl.com/?fruit=apples&fruit=Oranges
So:
cgi.params["fruit"] #=> ["apples","oranges"]
If you intend to only allow one value to be submitted, just use Array#first:
fruit = cgi.params["fruit"].first #=> "apples"
I used to think that this was a frustrating syntax, but I now realize this
is an essential part of the HTTP spec.
···
John Long
www.wiseheartdesign.com