# How to pass a hash as a parameter in link\_to\_remote

**URL:** <https://www.ruby-forum.com/t/how-to-pass-a-hash-as-a-parameter-in-link-to-remote/58226>\
**Category:** Rails\
**Created:** [April 19, 2006, 8:32pm UTC](https://www.ruby-forum.com/t/how-to-pass-a-hash-as-a-parameter-in-link-to-remote/58226 "2006-04-19T20:32:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [April 19, 2006, 8:32pm UTC](https://www.ruby-forum.com/t/how-to-pass-a-hash-as-a-parameter-in-link-to-remote/58226/1 "2006-04-19T20:32:21Z")

</div>

When using link\_to\_remote, I’d like to pass along some auxiliary data in  
the request. It’s a hash of dynamic data that can change with each  
request.

But I get an error when rails trying to “stringify” the hash.

For the regular link\_to, it works because it turns the hash into a  
regular GET-like query string.

I’m expecting to be able to get my hash as

params[:myhash] # =\> my hash data

inside my controller action, but this only works for link\_to, not  
link\_to\_remote.

My workaround was to write my own helper method to convert the hash into  
a querystring-looking string, and then to de-stringify inside the  
controller.

But I feel like I must be reinventing the wheel. What’s the correct way  
to pass a hash to my controller in an ajax call?

Thanks!  
Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [April 20, 2006, 1:13am UTC](https://www.ruby-forum.com/t/how-to-pass-a-hash-as-a-parameter-in-link-to-remote/58226/2 "2006-04-20T01:13:22Z")

</div>

Jeff,  
I recently saw the same sort of discussion on the Utah Ruby U.  
Group  
list. Here’s a link for the start of the tread. Just follow it through  
and  
hopefully you can find your answer.

[http://comox.textdrive.com/pipermail/talk/2006-April/000965.html](http://comox.textdrive.com/pipermail/talk/2006-April/000965.html)

Rob

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [April 20, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/how-to-pass-a-hash-as-a-parameter-in-link-to-remote/58226/3 "2006-04-20T17:47:11Z")

</div>

Thanks for the link Rob. That’s exactly what I needed.

For those interested, the best answer seems to be (from Jamis) to base64  
your hash, and decode it later.

string = Base64.encode64(Marshal.dump(hash)).strip  
hash = Marshal.load(Base64.decode64(string))

Brian

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software
