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 read in some of the ClickOnce posts that ClickOnce does not allow
I have some code like this: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Save([Bind(Prefix=)]Person person) { String s
I have to POST some parameters to a URL outside my network, and the
Does anyone have some sample code showing how to POST to a URL using
I have a Rails app that will post some data to another Rails app.
I'm using httpc:request to post some data to a remote service. I have the
Suppose you have a method with some pre and post-conditions. Is it ok to
I have some UI in VB 2005 that looks great in XP Style, but
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart

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.