How to implement a 'safe' periodical executer without using the Rails helpers?

Posted by Robbie on Stack Overflow See other posts from Stack Overflow or by Robbie
Published on 2010-05-08T19:09:32Z Indexed on 2010/05/09 23:48 UTC
Read the original article Hit count: 219

I am very new to Ruby on Rails and was never really big on writing JavaScript, so the built in helpers were like a tiny silce of heaven. However I have recently learned that using the helper methods creates "obtrusive javascript" so I am doing a tiny bit of refactoring to get all this messy code out of my view. I'm also using the Prototype API to figure out what all these functions do.

Right now, I have:

<%= periodically_call_remote(:url => {:action => "tablerefresh", :id => 1 }, :frequency => '5', :complete => "load('26', 'table1', request.responseText)")%>

Which produces:

<script type="text/javascript"> 
    //<![CDATA[
    new PeriodicalExecuter(function() {new Ajax.Request('/qrpsdrail/grids/tablerefresh/1', {asynchronous:true, evalScripts:true, onComplete:function(request){load('26', 'table1', request.responseText)}, parameters:'authenticity_token=' + encodeURIComponent('dfG7wWyVYEpelfdZvBWk7MlhzZoK7VvtT/HDi3w7gPM=')})}, 5)
    //]]>
</script>

My concern is that the "encodeURIComponent" and the presence of "authenticity_token" are generated by Rails. I'm assuming these are used to assure the validity of a request. (Ensuring a request comes from a currently active session?)

If that is the case, how can I implement this in application.js 'safely'? It seems that the built in method, although obtrusive, does add some beneficial security.

Thanks, in advance, to all who answer.

© Stack Overflow or respective owner

Related posts about prototype

Related posts about JavaScript