Will paginate (3.0.3) doesn’t work with inherited resources (1.3.1). In my controller:
protected
def collection
@posts ||= end_of_association_chain.paginate(:page => params[:page])
end
I added require ‘will_paginate/array’ in my initializer, but this doesn’t fix the problem. How can i get working will paginate and inherited resources together? In my views i get error
undefined method `total_pages' for #<ActiveRecord::Relation:0x00000004312e38>
This is kind of a long shot, but I ran into this problem and it turns out it was CanCan, another gem I am using. This was one of the first things I stumbled on, so I figured it may help someone one day.
Check out: https://github.com/ryanb/cancan/wiki/Inherited-Resources
The call to
load_and_authorize_resourceloads the collection so the right side of the conditional assignment never gets run in thecollectionmethod. The fix that is described in the link above is to skip authorization for collection actions, and do the check explicitly in thecollectionmethod.I hope that helps someone.