Collection has next question


#1

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?


#2

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?


#3

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/

Regards,

-- Jean-François.