Auto rotating between (will_)paginated objects?

Ok lets see if I can ask this question in a way that makes sense...

I have a website that has a testimonial box on the front page that show one testimonial at a time. I pull the testimonials using will_paginate and 1 object for 1 page. There is next | prev links under this box that uses ajax to pull the next object. This works great and I'm happy with this solution but now I would like to auto rotate this testimonial box if the user do not press the next link?

I looked at a few solutions but could not get them to work correctly.

The closest I got was using periodically_call_remote but when I put this in my partial it looks like it adds a new script every time it updates ? I had it set to 10 seconds and after 10 seconds it started changing faster and faster... until it was just flashing...

Any ideas?

I knew there was something I left out of the initial post... :slight_smile: Since the setup uses will_paginate I have to pass the 'next_page' page to the ajax_call or else the call that goes here :

  def paginate     @testimonial = Testimonial.paginate(         :page => params[:page],         :conditions => "testimonial_type = 'customer' AND frontpage = 1")

    respond_to do |format|       format.js { testimonial_crossfade }     end   end

and gives the same testimonial

here is the remote call

<%= periodically_call_remote(:url => {:action => 'paginate'}, :frequency => 5)%>

so what I was trying todo was to use the will_paginate helper next_page like this:

<%= periodically_call_remote(:url => {:action => 'paginate', :page => @testimonial.next_page}, :frequency => 5)%>

but then I have to update the call every time I make the remote call...

good point :wink:

you'll have to configure the thing then

one of those should do:

:submit: Specifies the DOM element ID that‘s used as the parent of the form elements. By default this is the current form, but it could just as well be the ID of a table row or any other DOM element.

:with: A JavaScript expression specifying the parameters for the XMLHttpRequest. Any expressions should return a valid URL query string.

:with => "'name=' + $('name').value"

so you could add a hidden field or whatever that your ajax call updates with the next_page number.

IF your response is fast enough...

otherwise you could use

:condition: Perform remote request conditionally by this expression. Use this to describe browser-side conditions when request should not be initiated.

to block the call temporarily, until your response unlocks it again...

Thanks!! :with was the missing link for me..

Everything is now working just like I wanted....