Module: Shaf::Paginate
- Defined in:
- lib/shaf/helpers/paginate.rb
Instance Method Summary collapse
- #current_page ⇒ Object
- #paginate(collection, per_page = PAGINATION_PER_PAGE) ⇒ Object
- #paginate!(collection, per_page = PAGINATION_PER_PAGE) ⇒ Object
Instance Method Details
#current_page ⇒ Object
4 5 6 7 |
# File 'lib/shaf/helpers/paginate.rb', line 4 def current_page page = (params[:page] || 1).to_i page == 0 ? 1 : page end |
#paginate(collection, per_page = PAGINATION_PER_PAGE) ⇒ Object
20 21 22 |
# File 'lib/shaf/helpers/paginate.rb', line 20 def paginate(collection, per_page = PAGINATION_PER_PAGE) paginate!(collection.dup, per_page) end |
#paginate!(collection, per_page = PAGINATION_PER_PAGE) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/shaf/helpers/paginate.rb', line 9 def paginate!(collection, per_page = PAGINATION_PER_PAGE) unless collection.respond_to? :paginate log.warning "Trying to paginate a collection that doesn't " \ "support pagination: #{collection}" return end per_page = params[:per_page].to_i if params[:per_page] collection.paginate(current_page, per_page) end |