# Help me understand what to\_param does on a hash

**URL:** <https://www.ruby-forum.com/t/help-me-understand-what-to-param-does-on-a-hash/162092>\
**Category:** Rails\
**Created:** [March 5, 2009, 5:47pm UTC](https://www.ruby-forum.com/t/help-me-understand-what-to-param-does-on-a-hash/162092 "2009-03-05T17:47:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ehudros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@ehudros](https://www.ruby-forum.com/u/ehudros)\
**Post date:** [March 5, 2009, 5:47pm UTC](https://www.ruby-forum.com/t/help-me-understand-what-to-param-does-on-a-hash/162092/1 "2009-03-05T17:47:06Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![ehudros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@ehudros](https://www.ruby-forum.com/u/ehudros)\
**Post date:** [March 5, 2009, 6:24pm UTC](https://www.ruby-forum.com/t/help-me-understand-what-to-param-does-on-a-hash/162092/2 "2009-03-05T18:24:21Z")

</div>

On 5 Mar 2009, at 16:47, Ehud R. 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
