Why does Post.page(1).total_pages result in:
Post.page(1).total_pages
undefined local variable or method `total_pages' for #<ActiveRecord::Relation:0x00000006a95230>
but
Post.scoped.page(1).total_pages
works fine. Curiously,
Post.paginate(:page => 1).total_pages
works fine. I looked at the code on Github ( https://github.com/mislav/will_paginate/blob/master/lib/will_paginate/active_record.rb ) and I can see why paginate works (because it calls limit first... which returns an active record relation, much like scoped does). I have a feeling it has something to do with this code
rel = scoped.extending(RelationMethods)
I guess I don't understand the difference between these the active record relation that limit returns versus scoped.extending(RelationMethods). Any ideas?
This only happens when using the rails_admin gem. It works fine in a fresh Rails 3.1.1 app with will_paginate 3.0.2.
Rails admin is probably doing something to the page method, though I'm not sure what exactly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With