How do you refresh js variables after loading a new partial in RoR?

In a javascript file, I pull off this rails variable from my view:

this.main_id = <%= images[0].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.

Answers


add these line at the end of partials

<script> this.main_id=<%=images[0].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[0].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.


Need Your Help

how to add serial number with text points in crystal report?

c# .net crystal-reports crystal-reports-xi

I want to design a crystal report that will have text with serial number(just like bullted points)

Big number and lost of precision

dart

I do this operation and I want result without exponents :

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.