# Auto rotating between (will\_)paginated objects?

**URL:** <https://www.ruby-forum.com/t/auto-rotating-between-will-paginated-objects/139101>\
**Category:** Rails\
**Created:** [May 30, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/auto-rotating-between-will-paginated-objects/139101 "2008-05-30T19:09:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![heimdull](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@heimdull](https://www.ruby-forum.com/u/heimdull)\
**Post date:** [May 30, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/auto-rotating-between-will-paginated-objects/139101/1 "2008-05-30T19:09:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![heimdull](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@heimdull](https://www.ruby-forum.com/u/heimdull)\
**Post date:** [May 30, 2008, 7:14pm UTC](https://www.ruby-forum.com/t/auto-rotating-between-will-paginated-objects/139101/2 "2008-05-30T19:14:20Z")

</div>

> 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…

Sure, if the periodically\_call\_remote is part of your partia, then it’ll  
be installed over and over again.  
Split your partial and don’t resend the periodically\_call\_remote with  
every ajax response

---

<div class="post-metadata">

**Author:** ![heimdull](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@heimdull](https://www.ruby-forum.com/u/heimdull)\
**Post date:** [May 30, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/auto-rotating-between-will-paginated-objects/139101/3 "2008-05-30T19:30:52Z")

</div>

I knew there was something I left out of the initial post… 🙂 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…

---

<div class="post-metadata">

**Author:** ![heimdull](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@heimdull](https://www.ruby-forum.com/u/heimdull)\
**Post date:** [May 30, 2008, 9:03pm UTC](https://www.ruby-forum.com/t/auto-rotating-between-will-paginated-objects/139101/4 "2008-05-30T21:03:50Z")

</div>

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

Everything is now working just like I wanted…

---

<div class="post-metadata">

**Author:** ![heimdull](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@heimdull](https://www.ruby-forum.com/u/heimdull)\
**Post date:** [May 30, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/auto-rotating-between-will-paginated-objects/139101/5 "2008-05-30T19:46:10Z")

</div>

good point 😉

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…
