by
back

Using gem active_admin with will_paginate

If you try to use the ruby gem will_paginate together with the gem active_admin in your rails app, then you will probably get the following error
Undefined Method `per' for #<ActiveRecord::Relation:...

The problem is, that active_admin uses the gem Kamiari for pagination and this gem uses the method per instead of per_page

An easy solution is to add an initializer to your app. There you can extend will_paginate to respond to this method :

/config/initializers/will_paginate.rb

if defined?(WillPaginate)
  module WillPaginate
    module ActiveRecord
      module RelationMethods
        def per(value = nil) per_page(value) end
        def total_count() count end
      end
    end
    module CollectionMethods
      alias_method :num_pages, :total_pages
    end
  end
end


comments powered by Disqus