# Link\_to\_remote :with hash

**URL:** <https://www.ruby-forum.com/t/link-to-remote-with-hash/140289>\
**Category:** Rails\
**Created:** [June 12, 2008, 5:33pm UTC](https://www.ruby-forum.com/t/link-to-remote-with-hash/140289 "2008-06-12T17:33:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [June 12, 2008, 5:33pm UTC](https://www.ruby-forum.com/t/link-to-remote-with-hash/140289/1 "2008-06-12T17:33:12Z")

</div>

I found myself doing a lot of long :with strings with link\_to\_remote  
when passing multiple parameters from the page by dom ids. This  
strings are really easy to mess up so I added a behavior to  
link\_to\_remote that allows me to pass a hash to the :with parameter  
like this -\>

link\_to\_remote “click me”,  
:url =\> {:action =\> ‘some\_action’},  
:with =\> {:parameter =\> :some\_dom\_id,  
:another\_parameter =\> :another\_dom\_id,  
“a[hash][parameter]” =\> :dom\_id\_3}

I added this to environment.rb

ActionView::Helpers::PrototypeHelper.class\_eval do  
def link\_to\_remote\_with\_with\_hash(text, args)  
if Hash == args[:with].class  
args[:with] = “’” \<\< args[:with].collect{|var, val|  
“#{var}=’ + encodeURIComponent($(’#{val}’).value)”  
}.inject{|str, el|  
str \<\< " + '&#{el}"  
}  
end  
link\_to\_remote\_without\_with\_hash(text, args)  
end  
alias\_method\_chain :link\_to\_remote, :with\_hash  
end

Just thought I’d share it.

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [June 12, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/link-to-remote-with-hash/140289/2 "2008-06-12T23:19:20Z")

</div>

Hi Julian,

That’s interesting. You should do a write-up. Maybe on the wiki, or in  
a  
blog.

Best regards,  
Bill
