eRuby and URL rewriting

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. URL Rewriting
      Hi all, I'm hoping someone can help me here. I've been using sesConverter to rewrite a url like this: ...
    2. 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...
    3. 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...
    4. 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...
    5. 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....
  3. #2

    Default Re: eRuby and URL rewriting

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

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

  4. #3

    Default 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

  5. #4

    Default Re: eRuby and URL rewriting

    "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.
    Eric Schwartz Guest

  6. #5

    Default Re: eRuby and URL rewriting



    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 Guest

  7. #6

    Default Re: eRuby and URL rewriting

    -- "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
    />
    <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

  8. #7

    Default Re: eRuby and URL rewriting

    * Bermejo, Rodrigo <rodrigo.bermejo@ps.ge.com> [1135 15:35]:
    >
    > [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"
    See below for an rhtml file
    > 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
    > >>given the following URL: [url]http://www.xyz.com/index.html?key=RUBYRULZ[/url]
    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']
    %><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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139