Sha256: 7effc6beb8b7c0c5226fe9d090480e4490ea7c2d343413706eadd8fcbd62602a

Contents?: true

Size: 726 Bytes

Versions: 7

Compression:

Stored size: 726 Bytes

Contents

module RailsDb
  module TablePagination

    def next_page
      current_page < total_pages ? (current_page + 1) : nil
    end

    def paginate(options = {})
      self.per_page     = (options[:per_page] || 10).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

    def previous_page
      current_page > 1 ? (current_page - 1) : nil
    end

    def total_entries
      @total_entries ||= count
    end

    def total_pages
      total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_db-0.5.1 lib/rails_db/table_pagination.rb
rails_db-0.5 lib/rails_db/table_pagination.rb
rails_db-0.4 lib/rails_db/table_pagination.rb
rails_db-0.3 lib/rails_db/table_pagination.rb
rails_db-0.2.1 lib/rails_db/table_pagination.rb
rails_db-0.2 lib/rails_db/table_pagination.rb
rails_db-0.1 lib/rails_db/table_pagination.rb