# Ideas for AJAX pagination

**URL:** <https://www.ruby-forum.com/t/ideas-for-ajax-pagination/98483>\
**Category:** Rails\
**Created:** [July 15, 2006, 12:06am UTC](https://www.ruby-forum.com/t/ideas-for-ajax-pagination/98483 "2006-07-15T00:06:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 15, 2006, 12:06am UTC](https://www.ruby-forum.com/t/ideas-for-ajax-pagination/98483/1 "2006-07-15T00:06:38Z")

</div>

Hi,

I am looking for ideas on how to remove the last item from a  
paginated page when a new item is inserted, thus leaving only 10  
elements on the page.

Currently I have a form that inserts with AJAX, but as expected, each  
post added to the page just increases the number of posts leaving 11  
on a page that should only be displaying 10.

I have unique ID’s for each post (e.g. post\_4, post\_5, etc) and the  
post with the lowest number is on the bottom of the page, can anyone  
think of a way to make the last post disappear when the new post is  
added?

Basically what i need to do is do a page.hide ‘page\_\<% lowest id %\>’

- where the lowest id is not a known integer.

Ideas?

~Jamie

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 15, 2006, 2:20am UTC](https://www.ruby-forum.com/t/ideas-for-ajax-pagination/98483/2 "2006-07-15T02:20:59Z")

</div>

On Friday, July 14, 2006, at 3:04 PM, Jamie Q. wrote:

> I have unique ID’s for each post (e.g. post\_4, post\_5, etc) and the  
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

You could just re-render the 10 items on the page and replace all of  
them.

\_Kevin

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 16, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/ideas-for-ajax-pagination/98483/3 "2006-07-16T22:42:03Z")

</div>

This is what I am already doing, I just need a way to get the ID of  
the last post so I can hide it when a new one is made. If I could get  
the ID of the lowest post on the page I would be able to do that.

~Jamie

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 15, 2006, 4:59am UTC](https://www.ruby-forum.com/t/ideas-for-ajax-pagination/98483/4 "2006-07-15T04:59:59Z")

</div>

I’m no expert with Rails or Ruby (I’ve only been using it for about a  
week),  
but it sounds like you want to do something like this:  
[http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates](http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates)

Cody adds an item to the list but its always the same. To change it you  
could just pass the post details through the action then page.hide "  
page\_#{@lowest\_id}" and then page.insert\_html “page\_#{@newpost.title” or  
something. (The syntax for insert\_html isn’t correct, but you should get  
the  
idea)

Thought it might help! It probably won’t but that’s where I’d start.

Chris

On 15 Jul 2006 00:20:18 -0000, Kevin O. \<

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 16, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/ideas-for-ajax-pagination/98483/5 "2006-07-16T22:42:30Z")

</div>

I guess I would save the scriptaculous overhead if I did it this way,  
but it seems like re-rendering everything would defeat the purpose of  
using ajax in the first place (avert unnecessary page-loads and  
provide a smooth UI).

~Jamie

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 16, 2006, 10:45pm UTC](https://www.ruby-forum.com/t/ideas-for-ajax-pagination/98483/6 "2006-07-16T22:45:41Z")

</div>

When the controller saves the actual record, the instance variable  
that contains the record should have the ID now.

@post = Post.new(params[:post])  
@post.save  
@last\_post\_id = @post.id

Then in the data loaded by the remote form you could simply:

Element.hide(“post\_\<%= @last\_post\_id %\>”)

Hope this helps,  
Rick Martinez

On 7/16/06, Jamie Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but it sounds like you want to do something like this:  
> Chris
> 
> > > elements on the page.  
> > > Basically what i need to do is do a page.hide ‘page\_\<% lowest id %\>’  
> > > You could just re-render the 10 items on the page and replace all of them.
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Rick Martinez  
Director of Technology  
Complexity Gaming
