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.
Ok, so the answer is, I think:
It will retrieve 6 posts, starting from the sixth.
edit2: About the limit([6, 12]), I find that strange:
So I don’t really see how it works with an array. But I obviously missed something. Do you see what?