Module: FmStore::Paging
- Included in:
- FmReader
- Defined in:
- lib/fm_store/paging.rb
Instance Method Summary collapse
Instance Method Details
#page ⇒ Object
18 19 20 21 |
# File 'lib/fm_store/paging.rb', line 18 def page skips, limits = [:skip_records], [:max_records] (skips && limits) ? (skips + limits) / limits : 1 end |
#paginate(opts = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fm_store/paging.rb', line 4 def paginate(opts = {}) [:max_records] = opts[:per_page] || 30 if opts[:page] [:skip_records] = (opts[:page].to_i - 1) * [:max_records].to_i end collection = execute(true) WillPaginate::Collection.create(page, per_page, count) do |pager| pager.replace(collection) end end |
#per_page ⇒ Object
23 24 25 |
# File 'lib/fm_store/paging.rb', line 23 def per_page ([:max_records] || 30).to_i end |