Forum: Ruby on Rails Collection has next question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John B. (Guest)
on 2006-04-12 13:21
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?
John B. (Guest)
on 2006-04-12 15:36
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?
Jean-François (Guest)
on 2006-04-12 16:09
(Received via mailing list)
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_...

http://svn.viney.net.nz/things/rails/plugins/acts_...

Regards,

    -- Jean-François.
This topic is locked and can not be replied to.