administrate: Issue: undefined method `per'

I am hitting this error no matter how many models I remove form my DashboardManifest when visiting localhost:3000/admin.

Currently running rails 4.2.4

The gem installed with no issues and the install ran perfectly with no issues. I chose to not configure anything until I could get the base up and running, however it looks like that is not possible. I checked to make sure all dependencies were also installed properly. Any ideas as to what could be causing this error?

method_missing - activerecord (4.2.4) lib/active_record/relation/delegation.rb

      elsif array_delegable?(method)
        to_a.public_send(method, *args, &block)
      elsif arel.respond_to?(method)
        arel.public_send(method, *args, &block)
      else
        super
      end
    end
  end
end

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

For the latest version (0.9.0), I had to change the following line (second line in the method) as suggested above from: resources = Administrate::Search.new(resource_resolver, search_term).run to: resources = Administrate::Search.new(scoped_resource, dashboard_class, search_term).run

Anyone who runs into this issue at point, @gentle-noah’s solution still works, but you need to add an extra line with the render locals block, like so: show_search_bar: show_search_bar?

Which would make it look like:

def index
    search_term = params[:search].to_s.strip
    resources = Administrate::Search.new(resource_resolver, search_term).run
    resources = order.apply(resources)
    resources = resources.paginate(:page => params[:page])
    page = Administrate::Page::Collection.new(dashboard, order: order)

    render locals: {
      resources: resources.paginate(:page => params[:page]),
      search_term: search_term,
      page: page,
      show_search_bar: show_search_bar?
   }
end

If you are using will_paginate, add this to one of the initializers and problem should be solved

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

Updated the index method in app/controllers/admin/application_controller.rb to:

  def index
     search_term = params[:search].to_s.strip
     resources = Administrate::Search.new(resource_resolver, search_term).run
     resources = order.apply(resources)
     resources = resources.paginate(:page => params[:page])     
     page = Administrate::Page::Collection.new(dashboard, order: order)

     render locals: {
       resources: resources.paginate(:page => params[:page]),
       search_term: search_term,
       page: page,
     }
   end

And strangely enough, the kaminari pagination links work great… SO, issue solved. Thank you for trouble shooting with me @graysonwright

ah, will_paginate…

Going to try the following:

Kaminari.configure do |config|
  config.page_method_name = :per_page_kaminari
end

Will report back soon.