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