# Replicating link\_to\_remote in raw js

**URL:** <https://www.ruby-forum.com/t/replicating-link-to-remote-in-raw-js/172042>\
**Category:** Rails\
**Created:** [July 13, 2009, 7:31pm UTC](https://www.ruby-forum.com/t/replicating-link-to-remote-in-raw-js/172042 "2009-07-13T19:31:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 13, 2009, 7:31pm UTC](https://www.ruby-forum.com/t/replicating-link-to-remote-in-raw-js/172042/1 "2009-07-13T19:31:51Z")

</div>

This is an interesting problem:

I have a view that has a div that gets replaced by innerhtml using a  
settimer() in js.

The settimer() invokes a js function (makemytable())that creates a  
table in html based on json data that gets written on the server every  
2 seconds.

So, every 2 seconds, the table in the div in the view automatically  
updates itself. So far, tres bien, very good.

Now, I need to put links in some of the cells in the table – but I  
want them to be effectively link\_to\_remote’s.

So waht I need to do is, since this innerhtml is finished html/js and  
not ruby code, I need to put these link\_to\_remotes in in a pure js  
manner from within makemytable(), which is itself a js.

So my question, the must be a way within js to replicate what  
link\_to\_remote creates, no? How can I write out the finished page, in  
effect, with links that operate like link\_to\_remote? Does anyone know  
what that looks like? If I simply look at the source of a page I have  
with a link\_to\_remote on it I see:

\<a href="#" onclick="new Ajax.Request(’/channels/userfreeze’,  
{asynchronous:true, evalScripts:true, parameters:‘authenticity\_token=’

- encodeURIComponent  
(‘xgorbWtiTdb15yhJ9il0TbbD1szBHSAcWb7p6GVffF0=’)}); return false;"  
style=“float: right; border-style: ridge; padding: 1px;” title=“Make  
user in box below be frozen” type=“submit”\> ![Freeze]()

I assume I only need copy this text, altering what needs to be altered  
interms of where I wantt it to call, etc. But what is the  
authenticity\_token? I am using AUthLogic plugin, could it be from  
that?. Is that necessary here to put that text in too? -Janna B

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [July 14, 2009, 2:38am UTC](https://www.ruby-forum.com/t/replicating-link-to-remote-in-raw-js/172042/2 "2009-07-14T02:38:24Z")

</div>

On Mon, Jul 13, 2009 at 10:31 AM, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> So, every 2 seconds, the table in the div in the view automatically  
> link\_to\_remote creates, no? How can I write out the finished page, in  
> images/freeze.gif?1247336897" /\>
> 
> I assume I only need copy this text, altering what needs to be altered  
> interms of where I wantt it to call, etc. But what is the  
> authenticity\_token? I am using AUthLogic plugin, could it be from  
> that?. Is that necessary here to put that text in too? -Janna B

Janna, it’s actually a feature of Rails to prevent  
cross site request forgery (CSRF)_. You can find_  
more details here:

[http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html](http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html)

Good luck,

-Conrad
