Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:50:05+00:00 2026-05-30T04:50:05+00:00

In a simple blog application where someone can read an article and decide to

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:50:07+00:00Added an answer on May 30, 2026 at 4:50 am

    You could add a method to Article to 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_at used to define the order

    def next
      self.class.find(
        :first, 
        :conditions => ["created_at > ?", self.created_at], 
        :order => 'created_at, id')
    end
    
    def previous
      self.class.find(
        :first, 
        :conditions => ["created_at < ?, self.created_at],
        :order => 'created_at desc, id desc')
    

    That 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:

        :conditions => ["created_at > ? or (created_at = ? and id > ?)", self.created_at, self.created_at, self.id]
    

    If you just want to order by id then it is even more trivial as the ids can never be the same:

    def next
      self.class.find(:first,
        :conditions => ['id > ?', self.id],
        :order => 'id')
    end
    
    def previous
      self.class.find(:first,
        :conditions => ['id < ?', self.id],
        :order => 'id desc')
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really simple blog application and I want to add a really
I have created a simple blog application with Ruby on Rails. The applications consists
I have built a very simple blog application using Ruby on Rails. New to
Let's say I have a simple ASP.NET MVC blog application and I want to
I have a cakePhp application built, and now I'm creating a simple blog based
I'm building a simple blog-style application. I really only need admin and non-admin users,
I have followed a tutorial to create a simple blog writing application in PHP
I have a simple blog application written in Python, using Django. I use Git
I am looking to create an application effectively like a very simple blog -
I have this simple code: <html> <head> <title>My Cake Blog Application</title> <?=$html->css('styles');?> </head> <body>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.