about summary refs log tree commit diff
path: root/app/models/concerns/paginable.rb
blob: 2d35d349fce521c1d778b33b63967ac82c145246 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
module Paginable
  extend ActiveSupport::Concern

  included do
    def self.paginate_by_max_id(limit, max_id = nil, since_id = nil)
      query = order('id desc').limit(limit)
      query = query.where('id < ?', max_id) unless max_id.blank?
      query = query.where('id > ?', since_id) unless since_id.blank?
      query
    end
  end
end