Class: Pagify::ActiveRecordPager
- Inherits:
-
BasicPager
- Object
- BasicPager
- Pagify::ActiveRecordPager
- Includes:
- PageAcceptStringOrBlank
- Defined in:
- lib/pagify/pager/active_record.rb
Overview
active_record paginator was provided for convenience, it wraps Paginator for you, and you can just pass the model class to it. you don’t have to care about the fetcher and counter. additionally, you can pass other options to rails paginator, they would be used in find options. e.g.,
ActiveRecordPaginator.new Model, :order => 'created_at DESC'
would invoke Model.find :all, :offset => ?, :limit => ?, order => ‘created_at DESC’
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
the model class that you passed in this paginator.
Attributes inherited from BasicPager
Instance Method Summary collapse
-
#initialize(model_class, opts = {}) ⇒ ActiveRecordPager
constructor
A new instance of ActiveRecordPager.
Methods inherited from BasicPager
#==, #each, #entries_count, #offset, #page, #page_exists?, #size, #to_a
Constructor Details
#initialize(model_class, opts = {}) ⇒ ActiveRecordPager
Returns a new instance of ActiveRecordPager.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pagify/pager/active_record.rb', line 17 def initialize model_class, opts = {} @model = model_class query_opts = reject_pager_opts(opts) super(opts.merge( :fetcher => lambda{ |offset, per_page| model.find(:all, query_opts.merge(:offset => offset, :limit => per_page)) }, :counter => lambda{ model.count(query_opts) })) end |
Instance Attribute Details
#model ⇒ Object (readonly)
the model class that you passed in this paginator
15 16 17 |
# File 'lib/pagify/pager/active_record.rb', line 15 def model @model end |