ng_will_paginate makes it easy to use the will_paginate gem with Angular, everyone's favorte Javascript framework.

Normal use of will_paginate gem requires a page reload. Trying to paginate with AJAX on a single page requires quite a bit of extra work. This gem does that work for you.

This allows you to use the will_paginate gem via an Angular controller. User pushes button on page, triggering a method in Angular controller that calls a Rails controller for selected page of records.


  • service that talks to rails
  • directive that puts links on page


Add this line to your application's Gemfile:

gem 'will_paginate'
gem 'ng_will_paginate'

And then execute:

$ bundle

Add '//= require ng_will_paginate' to your application.js manifest

Add 'ng-will-paginate' as a dependency of your Angular app: angular.module('myModule', ['ng-will-paginate'])


To use ng_will_paginate, first include the logic to retrieve your records from your database.

In your Rails controller:

def index
  @records = MyClass.paginate(:page => params[:page], :per_page => 10).order(created_at: 'desc')

  render json: {  max: @records.total_pages,
                  records: @records.as_json() }

The .as_json() method can accept all of it's normal options. See the .to_JSON documentation for examples

In your Angular controller:

  1. inject $scope and paginationService into your controller coffeescript myApp.controller 'myController', ['$scope', 'paginationService', ($scope, paginationService)-> //the controller code ]
  2. add the following code to your controller ```coffescript $scope.route = '/my_route' //this is the path for your method, if the index method above was for a class called 'Record', the path may look like '/records'

$scope.goToPage=(pageNumber)-> paginationService.getPage(pageNumber, $scope.route, $scope)

$scope.goToPage 1

Now your records will be available as an array of JSON object in $scope.records

3. in your view

When triggering on page, pass model name like in WP. Setup includes which Rails endpoint each model name can go to.


After checking out the repo, run bin/setup to install dependencies. Then, 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. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to


We love testing - so we want to test all the things.

To run jasmine tests:

  1. Navigate from the gem's repo to the dummy app cd spec/dummy
  2. Start a server rails s
  3. In your browser navigate to "localhost:3000/specs"


Issues and tasks are in the Issues for this repo. We'd love your help!

Please comment on an Issue if you'd like to work on it, and submit a Pull Request when the work is done. All code should be tested.

  1. Fork it ([my-github-username]/ng_will_paginate/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

About NIRD

alt text

Grace_period is maintained and funded by NIRD LLC. The names and logos of NIRD are trademarks of NIRD LLC. We are committed to giving back to the open source community. We are available for hire.


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