Rails: activeadmin, undefined method `per' for #

后端 未结 8 1309
暖寄归人
暖寄归人 2021-02-02 18:15

I installed ActiveAdmin successfully:

My gemfile code:

source \'https://rubygems.org\'

 gem \'rails\', \'3.2.10\'

 # Bundle edge Rails instead:
         


        
相关标签:
8条回答
  • 2021-02-02 18:47

    If you are using kaminari and will_paginate together, you will definitely face this error. In short, kaminari and will_paginate are incompatible to each other. If you are using rails_admin (which uses kaminari for pagination) and also using will_paginate, you will need to add the following code to one of the initializers under config directory or you can create a new file, let say with name'will_paginate' add the code, and place it into initializers directory.

    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
    
    0 讨论(0)
  • 2021-02-02 18:49

    You can create an Initializer for Kaminari, like this:

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

    In my experience, I had to restart the server to make it work. That's all.

    0 讨论(0)
提交回复
热议问题