From: Jano Svitok Date: 2008-05-14T23:05:02+09:00 Subject: Re: how to do the equivalent of PHP's "$_GET" in Ruby? On Wed, May 14, 2008 at 3:39 PM, John Zorko wrote: > > Matthew, > > Indeed, this is a Rails question ... i'm new to this :-) > > My next question is -- what is the structure of the params hash i.e. how do > I access it's name / value pairs without knowing in advance what the name > will be? To use your example: > > GET /controller/action/1?question_id=forsure > > I want to do something like this: > > params.each { | param | do > url << param[ :name ] << "=" << param[ :value ] << "&" > end > > ... but I don't know how to refer to the name / value (I used :name and > :value here to get the point across). > > Regards, > > John 1. Please bottom post (i.e. write your reply under the previous one). It's easier to read. 2. For rails related questions, http://groups.google.com/group/rubyonrails-talk is more suitable - you'll get better/more specific answers there. Nonetheless, this is a nice ruby question, so here you go: params.each do | key, value| url << key << "=" << value << "&" end Notes: 1. it's either do...end or {...}, 2. each for Hash takes two-parameter block see http://ruby-doc.org/core/, class Hash. you'll find there a lot of nice and useful stuff. For this particular case, Enumerable#map and Array#join are handy: url = params.map {|key, value| "#{key}=#{value}" }.join('&') This way you won't have the trailing &. J.