Low commit activity in last 3 years
No release in over a year
View helpers for SmartPaginate. A simple, smart and clean pagination extension for Active Record and plain Ruby Arrays.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 5.0
~> 13.0

Runtime

 Project Readme

SmartPagination

SmartPagination adds view helpers for SmartPaginate. A simple, smart and clean pagination extension for Active Record and plain Ruby Arrays:

  • Simple: Easy to use, with a simple interface. It just does pagination, nothing more.
  • Smart: Can navigate through the pages without having to do an expensive count query. SmartPaginate will actually fetch one record more than needed and use it to determine if there's a next page.
  • Clean: The code is as minimal as possible while still useful. SmartPaginate does not auto include itself or monkey patch any classes.

For more details you can check SmartPaginate at https://github.com/ppostma/smart_paginate.

Gem Version Build Status Code Climate

Installation

Add this line to your application's Gemfile:

gem 'smart_pagination'

And then execute:

$ bundle

Or install it yourself as:

$ gem install smart_pagination

Usage

To enable pagination in an Active Record model, include the SmartPagination or SmartPaginate concern in your class:

class User < ActiveRecord::Base
  include SmartPagination
end

Then you can use the paginate scope to paginate results:

@users = User.paginate(page: params[:page], per_page: params[:per_page])

And finally you can use the smart_pagination_for or pagination_for helper in your views to render the pagination links:

<%= smart_pagination_for(@users) %>

If you want to render only previous and next links, you can use the smart_pager_for or pager_for helper in your views:

<%= smart_pager_for(@users) %>

If you want to render the pagination information text (Displaying x of y Items), you can use the smart_pagination_info_for or pagination_info_for helper in your views:

<%= smart_pagination_info_for(@users) %>

There are a number of options you can use to customize the pagination links. The default options are:

options = {
  info_mode:      false,
  pager_mode:     false,
  auto_hide:      false,
  item_class:     '',
  previous_text:  '&laquo;',
  previous_class: 'previous',
  next_text:      '&raquo;',
  next_class:     'next',
  active_class:   'active',
  disabled_class: 'disabled',
  wrapper:        'ul',
  wrapper_class:  'pagination',
  item_wrapper:   'li',
  inner_window:    2,
  outer_window:    0
}

smart_pagination_for(@users, options)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/smart-pagination.

License

The gem is available as open source under the terms of the MIT License.