Trying to understand periodically_call_remote() javascript prototype helper

E

explainer

I have the following code snippet on the documents#index view page of
my rails app.

<%= periodically_call_remote(
:url => {:controller => 'documents', :action => 'index'},
:update => 'documents',
:method => 'get' )
%>

The page shows a table of document records. Since these records can
be updated asynchronously by a message broker feed, I want the above
code to activate every 10 seconds (the default) and refresh the page.

Now, the page has a sidebar and when the time ticks the first time, I
get a complete copy of the entire page, including the sidebar,
inserted into the main table section of the page. I think the problem
is in specifying the :update => 'documents' div, but I just don't get
how to scope the region to be updated.

I can supply more info, such as the layout page and so forth, just ask.
 
B

Brian Candler

explainer said:
I have the following code snippet on the documents#index view page of
my rails app.

<%= periodically_call_remote(
:url => {:controller => 'documents', :action => 'index'},
:update => 'documents',
:method => 'get' )
%>

The page shows a table of document records. Since these records can
be updated asynchronously by a message broker feed, I want the above
code to activate every 10 seconds (the default) and refresh the page.

Now, the page has a sidebar and when the time ticks the first time, I
get a complete copy of the entire page, including the sidebar,
inserted into the main table section of the page.

Please ask Rails questions on the Rails mailing list in future. This
mailing list is for Ruby (the programming language) not Rails (the web
framework).

But for a quick answer, I suspect that you need to check in your
controller for an AJAX request and return only the part of the page you
want inserted, not the whole page.

e.g.

if request.xhr?
render :partial=>"something", :eek:bject=>something
else
... do normal HTML rendering
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top