How do you refresh js variables after loading a new partial in RoR?
this.main_id = <%= images.id %>;
Then I use Ajax to load a partial into a portion of the page (the view in question):
var url = '/images/thumbnails_newest/'+ this.main_id; new Ajax.Updater(this.scroller, url);
Now the js variable this.main_id has changed... I don't know how to access rails variable in the partial... I would like to update this value.
this.main_id = this.main_id in the partial.
Is there any way to do this? Thanks.
add these line at the end of partials
<script> this.main_id=<%=images.id%>; </script>
or define some JS method that can set the value of this.main_id and it takes one paramerter that will be image_id and call it at the end of partial assume JS method name is set_main_id then call it at then of partial code as below
<script> set_main_id(<%=images.id%>); </script>
actually what code in script tag run on client side, client already have previous all content when new content come then this js will update the previous one. hope it will help you.