Forum: Ruby on Rails help me understand what to_param does on a hash

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6fe135329ce89e00b74839a41c8e3872?d=identicon&s=25 Ehud Rosenberg (ehudros)
on 2009-03-05 17:47
Hi all,
I'm trying to track down the source of the to_param method for hashes.
let's say I have a hash like this: {:b=>"This is a description",
:a=>"1"}
what I currently get from to_param is "a=1&b=This+is+a+description"
which is both sorted and escaped.
The problem is I need the values to be URI escaped (a space should be
%20, not a +) and I can't figure out an easy way to do it. I also can't
track down the actual source (for example, how does the sorting takes
place?)

can someone help out?
Thanks :)
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-05 18:24
(Received via mailing list)
On 5 Mar 2009, at 16:47, Ehud Rosenberg wrote:

>
> Hi all,
> I'm trying to track down the source of the to_param method for hashes.
> let's say I have a hash like this: {:b=>"This is a description",
> :a=>"1"}
> what I currently get from to_param is "a=1&b=This+is+a+description"
> which is both sorted and escaped.
> The problem is I need the values to be URI escaped (a space should be
> %20, not a +) and I can't figure out an easy way to do it. I also
> can't

CGI::escape disagrees

> track down the actual source (for example, how does the sorting takes
> place?)

It's in active_support/core_ext/hash/conversions.rb

Fred
This topic is locked and can not be replied to.