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 3957746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:31:44+00:00 2026-05-20T02:31:44+00:00

So I have some posts, and would like to show n .. m most

  • 0

So I have some posts, and would like to show n..m most recent entries in the sidebar (these numbers being set in a config)

I can get the latest n records easily enough

class Post < ActiveRecord::Base
  default_scope :order => "created_at DESC"
  scope :published, lambda { where("blog_entries.created_at <= ?", Time.zone.now) }
  scope :latest, lambda { |n| published.limit(n) }
end

@posts = Post.latest(6)

But what I’d like is

@posts = Post.published.limit(6, 12)

but this gives wrong number of arguments, so is there any way in AR? Right now I’m playing with will_paginate, but it seems hacky to use it for this.

  • 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-20T02:31:45+00:00Added an answer on May 20, 2026 at 2:31 am

    Ok, so the answer is, I think:

    @posts = Post.published.limit(6).offset(5)
    

    It will retrieve 6 posts, starting from the sixth.


    edit2: About the limit([6, 12]), I find that strange:

    attr_accessor :limit_value
    
    def limit(value)
      relation = clone
      relation.limit_value = value
      relation
    end
    
    
    def build_arel
        ...
        arel.take(connection.sanitize_limit(@limit_value)) if @limit_value
        ...
    end
    
    
    def sanitize_limit(limit)
        if limit.is_a?(Integer) || limit.is_a?(Arel::Nodes::SqlLiteral)
          limit
        elsif limit.to_s =~ /,/
          Arel.sql limit.to_s.split(',').map{ |i| Integer(i) }.join(',')
        else
          Integer(limit)
        end
      end
    

    So I don’t really see how it works with an array. But I obviously missed something. Do you see what?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of items with some details that I would like to
I have read some posts having the same problem. I tried to adapt their
I have found some posts related to search on XML but those were not
I have read some posts on here about not mixing parameters when passing into
I have read some posts about this topic and the answers are comet, reverse
First of all, apologize because I have seen some posts about this, but I
I have already read some posts, but no one helped me with my problem.
I have a wordpress-generated page where I need some posts (in a specific category)
i have wordpress blog in my custom built website, i am displaying some posts
I have an webpage which posts some data and then redirects to a page

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.