Ask a Question related to Ruby, Design and Development.
-
Orion Hunter #1
eRuby and URL rewriting
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: [url]http://www.xyz.com/index.html?key=RUBYRULZ[/url]
Does eRuby have the equivalent?
__________________________________________________ _______________
Compare high-speed Internet plans, starting at $26.95.
[url]https://broadband.msn.com[/url] (Prices may vary by service area.)
Orion Hunter Guest
-
URL Rewriting
Hi all, I'm hoping someone can help me here. I've been using sesConverter to rewrite a url like this: ... -
CGI Authentication in eruby
Hello, What is the way to implement the functionality of php $PHP_AUTH_USER and $PHP_AUTH_PW in Ruby? I've looked on CGI and CGI:Session. but... -
latest mod_ruby and eruby ..
Would anyone out there know where to get the latest mod_ruby and eruby for the latest apache(2.0.47) for Windows and mswin32 ruby 1.8? I've look... -
Anyone have any luck with eruby on Windows?
I've read through the talk's archives quite a bit and there seems to have been some interest in eruby and mod_ruby on windows and several... -
my mod_ruby doesn't like my eruby
Hi, I'm not able to make eruby work with mod_ruby for some reason and I haven't found any solutions by looking at cases with a similar problem.... -
Rasputin #2
Re: eRuby and URL rewriting
* Orion Hunter <orion2480@hotmail.com> [1112 22:12]:
use CGI.rb for that kind of thing, it plays nicely with eruby.> 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: [url]http://www.xyz.com/index.html?key=RUBYRULZ[/url]
--
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
Rasputin Guest
-
Bermejo, Rodrigo #3
Re: eRuby and URL rewriting
[url]http://www.xyz.com/index.html?key=RUBYRULZ&key2=rubyrulz[/url]
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:
>* Orion Hunter <orion2480@hotmail.com> [1112 22:12]:
>
>>>>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: [url]http://www.xyz.com/index.html?key=RUBYRULZ[/url]
>>
>>
>use CGI.rb for that kind of thing, it plays nicely with eruby.
>
>
>
Bermejo, Rodrigo Guest
-
Eric Schwartz #4
Re: eRuby and URL rewriting
"Bermejo, Rodrigo" <rodrigo.bermejo@ps.ge.com> writes:
Actually, it's:> cgi.query_string.split("&").each {|x| p x }
> # "RUBYRULZ "
> #"rubyrulz"
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.
Eric Schwartz Guest
-
Bermejo, Rodrigo #5
Re: eRuby and URL rewriting
Eric Schwartz wrote:
Yeah a mistake...I'm not as cleaver as irb =)>"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,
>
Oh, I did know it .....modern browsers like ... ? ...just to be aware of> but FYI, it's broken in other ways too-- modern
>browsers are allowed to use ';' to separate variables in a GET
>request.
>
Thanks>In fact, I believe it is now the preferred form. Much
>friendlier to do:
>
>cgi.keys.each { |key| p cgi[key] }
>
BTW, I really don't understand why cgi['query'].class => Array ?>
>anyway :)
>
>-=Eric
>
>
-Ronnie.
Bermejo, Rodrigo Guest
-
John W. Long #6
Re: eRuby and URL rewriting
-- "Bermejo, Rodrigo" <rodrigo.bermejo@ps.ge.com> writes: --
Because it is possible to specify more than one value for param either in> BTW, I really don't understand why cgi['query'].class => Array ?
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
/>
<input type="submit" />
</form>
</body>
</html>
If you check Apples and Oranges, then press submit the following url will be
submitted:
[url]http://myurl.com/?fruit=apples&fruit=Oranges[/url]
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
[url]www.wiseheartdesign.com[/url]
John W. Long Guest
-
Rasputin #7
Re: eRuby and URL rewriting
* Bermejo, Rodrigo <rodrigo.bermejo@ps.ge.com> [1135 15:35]:
See below for an rhtml file>
> [url]http://www.xyz.com/index.html?key=RUBYRULZ&key2=rubyrulz[/url]
>
> require 'cgi'
> cgi = CGI.new
>
> key = cgi['key']
> p key
> # [ "RUBYRULZ " ]
> key.type
> # Array
> cgi.query_string.split("&").each {|x| p x }
> # "RUBYRULZ "
> #"rubyrulz"
> Rasputin wrote:
>> >* Orion Hunter <orion2480@hotmail.com> [1112 22:12]:
> >> >>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 likeFor the sake of completeness, here's a .rhtml example:> >>given the following URL: [url]http://www.xyz.com/index.html?key=RUBYRULZ[/url]
<% require 'cgi' # Require the CGI library
cgi = CGI.new() # New CGI object
key = cgi.params['key']
%><html><head><title>Test</title></head>
<body>
<% if key.empty? %>
<form method="post">
Please enter the key: <input type="text" name="key"><br>
<input type="submit" value="go"> </form>
<% else %>
the key is :<%= key %>
<% end %>
</body> </html>
--
Radioactive cats have 18 half-lives.
Rasputin :: Jack of All Trades - Master of Nuns
Rasputin Guest



Reply With Quote

