# Collection has next question

**URL:** <https://www.ruby-forum.com/t/collection-has-next-question/93862>\
**Category:** Rails\
**Created:** [April 12, 2006, 11:21am UTC](https://www.ruby-forum.com/t/collection-has-next-question/93862 "2006-04-12T11:21:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [April 12, 2006, 11:21am UTC](https://www.ruby-forum.com/t/collection-has-next-question/93862/1 "2006-04-12T11:21:28Z")

</div>

Hi,

I know about pagination but dont want to use that option if it all  
possible.

How in a collection of posts can i check if the there is a next item in  
the collection and then add that an object.

For instance:  
//Returns all the posts into a collection called posts  
@posts = Post.find(:all)

//Returns a specific post based on an id  
@post = Post.find(params[:id])

//How can i return the next post something similar to below. Do i need  
to write a custom Post.find\_next\_item(params:id) in the post model?  
@nextpost = Post.find(params[:id]).Next

Can anyone point me in the right direction?

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [April 12, 2006, 1:36pm UTC](https://www.ruby-forum.com/t/collection-has-next-question/93862/2 "2006-04-12T13:36:36Z")

</div>

Ive figured out how to do this.

All i need to know is how return the contents of 1 field from an sql  
statement on the posts table.

//This is a variable that i want the id of the next post to put into  
nextid = Post.find(:select =\> “id”,  
:conditions =\> “id \< 19”,  
:order =\> ‘id ASC LIMIT 1’)

This si the next post i want to find passing in the id from above.  
@nextpost = Post.find(params[nextid])

Any Examples, i cant find anything on the net?

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [April 12, 2006, 2:09pm UTC](https://www.ruby-forum.com/t/collection-has-next-question/93862/3 "2006-04-12T14:09:53Z")

</div>

Hello John,

> @nextpost = Post.find(params[nextid])
> 
> Any Examples, i cant find anything on the net?

you may find Jonathan V.'s plugin interesting :

acts\_as\_ordered :  
[http://svn.viney.net.nz/things/rails/plugins/acts\_as\_ordered/README](http://svn.viney.net.nz/things/rails/plugins/acts_as_ordered/README)

[http://svn.viney.net.nz/things/rails/plugins/acts\_as\_ordered/](http://svn.viney.net.nz/things/rails/plugins/acts_as_ordered/)

Regards,

```
-- Jean-FranÃ§ois.

```
