I\'m new in Rails... smile
In my blog aplication I want to have a \"Previous post\" link and a \"Next post\" link in the bottom of my show view.
How do I do
You really just need to run 2 queries, one for each of "prev" and "next". Lets assume you have a created_at column.
Psuedo-code:
# get prev
select * from posts where created_at < #{this_post.created_at} order by created_at desc limit 1
# get next
select * from posts where created_at > #{this_post.created_at} order by created_at desc limit 1
Of course "this_post" is the current post.
If your posts are stored with an auto_increment column and you dont re-use IDs you can just use the id column in place of created_at - the id column should already be indexed. If you want to use the created_at column then you will definitely want to have an index on that column.