module RailsDb::TablePagination
Constants
- DEFAULT_PAGINATION_PER_PAGE
Public Instance Methods
Source
# File lib/rails_db/table_pagination.rb, line 5 def next_page current_page < total_pages ? (current_page + 1) : nil end
Source
# File lib/rails_db/table_pagination.rb, line 9 def paginate(options = {}) self.per_page = (options[:per_page] || DEFAULT_PAGINATION_PER_PAGE).to_i self.current_page = (options[:page] || 1).to_i self.offset = (current_page * per_page) - per_page self.sort_column = options[:sort_column] self.sort_order = options[:sort_order] table end
Source
# File lib/rails_db/table_pagination.rb, line 18 def previous_page current_page > 1 ? (current_page - 1) : nil end
Source
# File lib/rails_db/table_pagination.rb, line 22 def total_entries @total_entries ||= count end
Source
# File lib/rails_db/table_pagination.rb, line 26 def total_pages total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil end