module RailsTableFor::Helpers::Paginate
Protected Instance Methods
current_page_records()
click to toggle source
# File lib/rails_table_for/helpers/paginate.rb, line 26 def current_page_records if paginated? start_index = (current_page_number - 1) * page_size records.slice(start_index, page_size) else records end end
pagination_links()
click to toggle source
# File lib/rails_table_for/helpers/paginate.rb, line 12 def pagination_links return '' unless paginated? content_tag :div, class: 'pagination-links' do (1..num_pages).map do |page_number| if page_number == current_page_number page_number.to_s else page_link(page_number) end end.join.html_safe end end
Private Instance Methods
current_page_number()
click to toggle source
# File lib/rails_table_for/helpers/paginate.rb, line 48 def current_page_number page = request_params[:page]&.to_i || 1 raise 'Invalid page number' if page < 1 || page > num_pages page end
num_pages()
click to toggle source
# File lib/rails_table_for/helpers/paginate.rb, line 41 def num_pages full_pages = record_count / page_size partial_final_page = (record_count % page_size).zero? ? 0 : 1 full_pages + partial_final_page end
page_link(page_number)
click to toggle source
# File lib/rails_table_for/helpers/paginate.rb, line 55 def page_link(page_number) path = request_path query = request_params.merge({ page: page_number }).to_query link_to page_number, "#{path}?#{query}" end
paginated?()
click to toggle source
# File lib/rails_table_for/helpers/paginate.rb, line 37 def paginated? page_size != nil end