In a simple blog application where someone can read an article and decide to read the next article without going through the list of articles again but click the next button and it takes the person to the next article on this list. How can this be done. I have worked with willpaginate and kaminari and they are both great plugins for pagination.
So now in the show action i want to have a next and previous link that featches the next and previous article how do i do this
simple code sample below to work with
def show
@article = Article.find(params[:id])
end
You could add a method to
Articleto get the next and previous articles depending on what you mean by next and previous – i.e. what order you want the articles in.E.g. with
created_atused to define the orderThat assumes that nothing has the same created at date which might be a bit too simplistic so you might want to check against the id too. Something like:
If you just want to order by id then it is even more trivial as the ids can never be the same: