01 May '12, 1pm

Don't construct query strings yourself! Let Hash#to_param do the heavy lifting.

Returns a string representation of the receiver suitable for use as a URL query string: { :name => ' David ', :nationality => ' Danish '}. to_param # => "name=David&nationality=Danish" An optional namespace can be passed to enclose the param names: { :name => ' David ', :nationality => ' Danish '}. to_param (' user ') # => "user[name]=David&user[nationality]=Danish" The string pairs “key=value” that conform the query string are sorted lexicographically in ascending order. This method is also aliased as to_query .

Full article: http://apidock.com/rails/v3.2.1/Hash/to_param

Tweets