# How to make a link containing 'link\_to\_remote' call and exec

**URL:** <https://www.ruby-forum.com/t/how-to-make-a-link-containing-link-to-remote-call-and-exec/112089>\
**Category:** Rails\
**Created:** [August 15, 2007, 8:28am UTC](https://www.ruby-forum.com/t/how-to-make-a-link-containing-link-to-remote-call-and-exec/112089 "2007-08-15T08:28:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![r.g](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e57/32.png) [@r.g](https://www.ruby-forum.com/u/r.g)\
**Post date:** [August 15, 2007, 8:28am UTC](https://www.ruby-forum.com/t/how-to-make-a-link-containing-link-to-remote-call-and-exec/112089/1 "2007-08-15T08:28:41Z")

</div>

Hey there,

I need to create a link that does both of the following in sequence:

1. updates an element using RJS, e.g.

\<%= link\_to\_remote h(video.title), :url =\> { :action  
=\> :do\_stuff, :id =\> video …

(with the ‘replace\_html’ call included in “do\_stuff.rjs”)

1. sends some javascript to a flash video player using a link  
generated from object data, e.g.

\<a href=“javascript:;” onclick="loadFile({file:’\<%= h video.url  
%\>’,title:’\<%= h video.title %\>’ …

I’ve gotten part 1 to work just fine. And of course, I can get part 2  
to work if I’m not trying to do part 1.  
So my question is: is there a way to perform both actions with the  
same link, so that a single click updates an element Ajax-style AND  
loads the video into my player?

I suspect this is possible using the "page \<\< " syntax in RJS. But I  
don’t see how I could write out a list of links using a partial on a  
collection of objects. I don’t have the option of replacing any HTML  
either, since I need the javascript actually executed, on the same  
click that also updates another element.

Any ideas? Thanks so much for any help you can give me.

---

<div class="post-metadata">

**Author:** ![r.g](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e57/32.png) [@r.g](https://www.ruby-forum.com/u/r.g)\
**Post date:** [August 15, 2007, 1:37pm UTC](https://www.ruby-forum.com/t/how-to-make-a-link-containing-link-to-remote-call-and-exec/112089/2 "2007-08-15T13:37:54Z")

</div>

> lsls

sorry bout that, i meant (in the onclick section) :

new Ajax.Updater(‘dom\_to\_update’, ‘/action/on/server/for/ajax’,  
{asynchronous:true, evalScripts:true}); LOAD\_FILE(\<%= rubyvars %\>);  
return false;

---

<div class="post-metadata">

**Author:** ![r.g](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e57/32.png) [@r.g](https://www.ruby-forum.com/u/r.g)\
**Post date:** [August 15, 2007, 1:34pm UTC](https://www.ruby-forum.com/t/how-to-make-a-link-containing-link-to-remote-call-and-exec/112089/3 "2007-08-15T13:34:36Z")

</div>

> Any ideas? Thanks so much for any help you can give me.

definitely not the most elegant solution, but quite a quick one - just  
copy the html that the link\_to\_remote puts out, and put the onclick  
function you need straight in there:

function LOAD\_FILE(var, var2, var3…) {  
//stuff  
}

lsls

---

<div class="post-metadata">

**Author:** ![r.g](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e57/32.png) [@r.g](https://www.ruby-forum.com/u/r.g)\
**Post date:** [August 15, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/how-to-make-a-link-containing-link-to-remote-call-and-exec/112089/4 "2007-08-15T19:38:17Z")

</div>

Thanks! I did what you suggested, although it seemed to work only if  
the call to my video player went first.  
But the desired result has been achieved.  
Thanks again.

On Aug 15, 4:37 am, Shai R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
