# Howto pass hashes in params?

**URL:** <https://www.ruby-forum.com/t/howto-pass-hashes-in-params/134317>\
**Category:** Rails\
**Created:** [April 9, 2008, 8:24pm UTC](https://www.ruby-forum.com/t/howto-pass-hashes-in-params/134317 "2008-04-09T20:24:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 9, 2008, 8:24pm UTC](https://www.ruby-forum.com/t/howto-pass-hashes-in-params/134317/1 "2008-04-09T20:24:50Z")

</div>

Hello,

i try to pass a hash in params.

h = Hash.new

[…]

\<%= link\_to ‘next’,:url =\> {:controller =\> ‘myController’, :action =\>  
‘myAction’, :h =\> h} %\>

The myController-controller:

def myController  
@h = params[:h]  
end

But it doesn’t work like this. Can someone give me a solution. Is it  
even possible to pass hashes in params?

regards

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 9, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/howto-pass-hashes-in-params/134317/2 "2008-04-09T22:29:26Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Hello,
> 
> i try to pass a hash in params.
> 
> h = Hash.new
> 
> […]
> 
> \<%= link\_to ‘next’,:url =\> {:controller =\> ‘myController’, :action =\>  
> ‘myAction’, :h =\> h} %\>
> 
> The myController-controller:
> 
> def myController  
> @h = params[:h]  
> end
> 
> But it doesn’t work like this. Can someone give me a solution. Is it  
> even possible to pass hashes in params?

Try this:

In a Controller:

params[:myhash] =\> { :aa =\> ‘hashaa’, :bb =\> ‘hashbb’ }

OR

In a view:

\<% @myhash = { :aa =\> ‘hashaa’, :bb =\> ‘hashbb’ } -%\>  
\<%= link\_to ‘next’,  
:controller =\> ‘myController’,  
:action =\> ‘myAction’,  
:mykey =\> @myhash %\>

Gives

— !map:HashWithIndifferentAccess  
action: new  
controller: entities  
mykey: !map:HashWithIndifferentAccess  
aa: hashaa  
bb: hashbb

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 10, 2008, 4:37am UTC](https://www.ruby-forum.com/t/howto-pass-hashes-in-params/134317/3 "2008-04-10T04:37:07Z")

</div>

James B. wrote:

> In a Controller:
> 
> params[:myhash] =\> { :aa =\> ‘hashaa’, :bb =\> ‘hashbb’ }

That should be:

params[:myhash] = { :aa =\> ‘hashaa’, :bb =\> ‘hashbb’ }
