Module: RailsDb::TablePagination
- Included in:
- TableData
- Defined in:
- lib/rails_db/table_pagination.rb
Constant Summary collapse
- DEFAULT_PAGINATION_PER_PAGE =
10
Instance Method Summary collapse
- #next_page ⇒ Object
- #paginate(options = {}) ⇒ Object
- #previous_page ⇒ Object
- #total_entries ⇒ Object
- #total_pages ⇒ Object
Instance Method Details
#next_page ⇒ Object
5 6 7 |
# File 'lib/rails_db/table_pagination.rb', line 5 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#paginate(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/rails_db/table_pagination.rb', line 9 def paginate( = {}) self.per_page = ([:per_page] || DEFAULT_PAGINATION_PER_PAGE).to_i self.current_page = ([:page] || 1).to_i self.offset = (current_page * per_page) - per_page self.sort_column = [:sort_column] self.sort_order = [:sort_order] table end |
#previous_page ⇒ Object
18 19 20 |
# File 'lib/rails_db/table_pagination.rb', line 18 def previous_page current_page > 1 ? (current_page - 1) : nil end |
#total_entries ⇒ Object
22 23 24 |
# File 'lib/rails_db/table_pagination.rb', line 22 def total_entries @total_entries ||= count end |
#total_pages ⇒ Object
26 27 28 |
# File 'lib/rails_db/table_pagination.rb', line 26 def total_pages total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil end |