Module: Cms::Behaviors::Pagination::ClassMethods
- Defined in:
- lib/cms/behaviors/pagination.rb
Instance Method Summary collapse
-
#paginate(*args, &block) ⇒ Object
This is the main paginating finder.
Instance Method Details
#paginate(*args, &block) ⇒ Object
This is the main paginating finder.
Special parameters for paginating finders
-
:page
– REQUIRED, but defaults to 1 if false or nil -
:per_page
– defaults toCurrentModel.per_page
(which is 30 if not overridden) -
:total_entries
– use only if you manually count total entries -
:count
– additional options that are passed on tocount
-
:finder
– name of the ActiveRecord finder used (default: “find”)
All other options (conditions
, order
, …) are forwarded to find
and count
calls.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/cms/behaviors/pagination.rb', line 131 def paginate(*args, &block) = args.pop page, per_page, total_entries = () finder = ([:finder] || 'find').to_s if finder == 'find' # an array of IDs may have been given: total_entries ||= (Array === args.first and args.first.size) # :all is implicit args.unshift(:all) if args.empty? end Collection.create(page, per_page, total_entries) do |pager| = .except :page, :per_page, :total_entries, :finder = .except(:count).update(:offset => pager.offset, :limit => pager.per_page) args << # @options_from_last_find = nil pager.replace send(finder, *args, &block) # magic counting for user convenience: pager.total_entries = count_for_pagination(, args, finder) unless pager.total_entries end end |