# \[Ajax on Rails\]How to pass an object via param

**URL:** <https://www.ruby-forum.com/t/ajax-on-rails-how-to-pass-an-object-via-param/181559>\
**Category:** Rails\
**Created:** [January 13, 2010, 8:27pm UTC](https://www.ruby-forum.com/t/ajax-on-rails-how-to-pass-an-object-via-param/181559 "2010-01-13T20:27:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![denommus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e99b99/32.png) [@denommus](https://www.ruby-forum.com/u/denommus)\
**Post date:** [January 13, 2010, 8:27pm UTC](https://www.ruby-forum.com/t/ajax-on-rails-how-to-pass-an-object-via-param/181559/1 "2010-01-13T20:27:36Z")

</div>

I’m trying to pass an object as a parameter on a link\_to\_remote. What  
I do is pretty simple:  
link\_to\_remote ‘Insert subquestion’, :url =\> {:action =\>  
‘add\_subquestion’, :question =\> @question}, :update =\> ‘’, :method  
=\> :get

But, obviously, what I get is a string which has the address of the  
object. Can I “translate” this string back to the object? Is there a  
better way to pass an object as a param?

---

<div class="post-metadata">

**Author:** ![denommus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e99b99/32.png) [@denommus](https://www.ruby-forum.com/u/denommus)\
**Post date:** [January 14, 2010, 4:09pm UTC](https://www.ruby-forum.com/t/ajax-on-rails-how-to-pass-an-object-via-param/181559/2 "2010-01-14T16:09:20Z")

</div>

But it’s a new object. It doesn’t have any id yet.  
But I think I have a solution. Instead of passing an id, adress or  
object\_id, I’ll pass it’s subquestion’s array length. Then all I have  
to do is put one more subquestion.  
Thank you, anyway.

---

<div class="post-metadata">

**Author:** ![denommus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e99b99/32.png) [@denommus](https://www.ruby-forum.com/u/denommus)\
**Post date:** [January 13, 2010, 8:29pm UTC](https://www.ruby-forum.com/t/ajax-on-rails-how-to-pass-an-object-via-param/181559/3 "2010-01-13T20:29:22Z")

</div>

On Jan 13, 7:04Â pm, Yuri [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to pass an object as a parameter on a link\_to\_remote. What  
> I do is pretty simple:  
> link\_to\_remote ‘Insert subquestion’, :url =\> {:action =\>  
> ‘add\_subquestion’, :question =\> @question}, :update =\> ‘’, :method  
> =\> :get
> 
> But, obviously, what I get is a string which has the address of the  
> object. Can I “translate” this string back to the object?

No. There is no way I know of to translate an address back into an  
actual object (although writing a ruby extension to do that is  
probably possible). Anyway, the request may have gone to a different  
mongrel or the original object may have been garbage collected

> Is there a  
> better way to pass an object as a param?

pass its id

Fred
