# Link\_to\_remote 'this'

**URL:** <https://www.ruby-forum.com/t/link-to-remote-this/159254>\
**Category:** Rails\
**Created:** [February 2, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/link-to-remote-this/159254 "2009-02-02T20:00:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [February 2, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/link-to-remote-this/159254/1 "2009-02-02T20:00:31Z")

</div>

When using something like

link\_to\_function “Label”, “some\_function(this);”

the ‘this’ references the href generated by the rails  
link\_to\_function.

When using something like

link\_to\_remote(task.id\_description,  
{:update =\> {:success =\> “div1”, :failure =\> “div2”},  
:url =\> {:action =\> :some\_action, :id =\> id},  
:id =\> id,  
:before =\> “Element.show(‘spinner’)”,  
:complete =\> “Element.hide(‘spinner’); some\_function(this)”})

the ‘this’ references something different, I believe the Ajax call  
itself.

Is there a way of accessing the href as you can in the  
link\_to\_function? I want to be able to access it so I can change its  
className to indicate its been selected and change all the other hrefs  
on the same level to be unselected.

Thanks

---

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [February 2, 2009, 8:14pm UTC](https://www.ruby-forum.com/t/link-to-remote-this/159254/2 "2009-02-02T20:14:40Z")

</div>

You should be able to do this:

link\_to\_remote(task.id\_description,  
{:update =\> {:success =\> “div1”, :failure =\> “div2”},  
:url =\> {:action =\> :some\_action, :id =\> id},  
:id =\> id,  
:before =\> “Element.show(‘spinner’)”,  
:complete =\> “Element.hide(‘spinner’); some\_function(’#  
{id}’)”})

---

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [February 2, 2009, 8:31pm UTC](https://www.ruby-forum.com/t/link-to-remote-this/159254/3 "2009-02-02T20:31:46Z")

</div>

Isn’t that just going to pass in the value of the variable ‘id’?

‘this’ actually references an object in the DOM and thats what I need  
from the function\_to\_remote so I can then manipulate it and other  
objects in relation to its position within the DOM.

Thanks

---

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [February 5, 2009, 6:08pm UTC](https://www.ruby-forum.com/t/link-to-remote-this/159254/4 "2009-02-05T18:08:01Z")

</div>

Hey Ben,

So when I put my code snippet in my app, this is the rendered html:

Ruby:  
\<% id = “user\_#{@user.id}” %\>  
\<%= link\_to\_remote(@user.login,  
:update =\> {:success =\> “div1”, :failure =\> “div2”},  
:url =\> {:action =\> :some\_action, :id =\> :some\_id},  
:before =\> “Element.show(‘spinner’)”, :complete =\>  
“Element.hide(‘spinner’); some\_function(’#{id}’)”,  
:html =\> {:id =\> id})  
%\>

HTML:  
removed\_email\_address@domain.invalid

Is this what you are looking for?
