Module: RailsDb::TablePagination
- Included in:
- TableData
- Defined in:
- lib/rails_db/table_pagination.rb
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
4 5 6 |
# File 'lib/rails_db/table_pagination.rb', line 4 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#paginate(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/rails_db/table_pagination.rb', line 8 def paginate( = {}) self.per_page = ([:per_page] || 10).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
17 18 19 |
# File 'lib/rails_db/table_pagination.rb', line 17 def previous_page current_page > 1 ? (current_page - 1) : nil end |
#total_entries ⇒ Object
21 22 23 |
# File 'lib/rails_db/table_pagination.rb', line 21 def total_entries @total_entries ||= count end |
#total_pages ⇒ Object
25 26 27 |
# File 'lib/rails_db/table_pagination.rb', line 25 def total_pages total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil end |