amatsuda/kaminari — pull request #304 by bricker88 (2012-11-01 01:17:21+00:00)
Title: Allow nil for #per, to return records without limit (like ActiveRelation#limit)

This option would make the `per` scope consistent with how ActiveRecord's `limit` works. Incidentally, it is also how `will_paginate` functions.

```ruby
Post.count #=> 1000
Post.limit(nil).count #=> 1000
```

This commit would allow us to do something similar, by *explicitly* passing in nil. Leaving off `per` would still return the `default_per_page`:

```ruby
Post.count #=> 1000
Post.page(params[:page].per(nil).count #=> 1000
Post.page(params[:page].count #=> 25

```

This is useful when, for example, you're systematically setting the `per_page` attribute for each model, for an admin CMS, and for some sections, pagination doesn't make sense or would be wrong. It will help keep consistent queries throughout an application.

```ruby
class User < ActiveRecord::Base
def self.per_page
nil
end
end

class Post < ActiveRecord::Base
def self.per_page
50
end
end

class AdminController < ApplicationController
def index
@klass = params[:controller].singularize.camelize.constantize
@records = @klass.page(params[:page]).per(@klass.per_page)
end
end
```

This is an overly-simple example, but I think you can see how it could come in handy, and why it makes more sense to allow this, to keep consistent with ActiveRecord.