0

I'm trying to setup Rails Administrate - https://github.com/thoughtbot/administrate.

Following the docs:

  1. gem "administrate" in the Gemfile
  2. rails generate administrate:install
  3. "Restart your server, and visit http://localhost:3000/admin to see your new dashboard in action."

From the Rails log, when visiting localhost:3000/admin I see the following SQL query is executed:

Order Load (0.7ms) SELECT "orders".* FROM "orders" LIMIT $1 OFFSET $2 [["LIMIT", 25], ["OFFSET", 475]]

Why is the OFFSET put on 475?

But more importantly, how do set it to 0 or remove it at all?

UPDATE:

  • I'm using will_paginate too (possible conflict here?)
  • My Kaminari settings in: config/initializers/kaminari_config.rb:
Kaminari.configure do |config|
  config.default_per_page = 25
  config.max_per_page = nil
  config.window = 4
  config.outer_window = 0
  config.left = 0
  config.right = 0
  config.page_method_name = :per
  config.param_name = :page
  config.max_pages = nil
  config.params_on_first_page = false
end

SOLUTION

will_paginate was interfering with kaminari

I created an initializer for will_paginate:

# 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
        def first_page?() self == first end
        def last_page?() self == last end
      end
    end
    module CollectionMethods
      alias_method :num_pages, :total_pages
    end
  end
end

Now it works!

HJW
  • 342
  • 3
  • 13
  • 2
    Administrate doesn't set an offset (or in ActiveRecord a `:limit`) by default. This might be the result of something in your controller or model, or perhaps a strange interaction with a pagination gem. If you are getting this at `/admin`, I assume that your top admin route is `/admin/orders`, and therefore this SQL query is run within the action `Admin::OrdersController#index`. Is this correct? Would you be able to show us the controller and model involved? Do you have any pagination gem in your project that might be conflicting with Kaminari (used by Administrate)? – pablobm Aug 22 '20 at 18:11
  • Actually, I am indeed using `will_paginate` too. How do you think they interfere? I don't assume there's a problem with the controller nor model since this magix 475 number is in the other controllers as well. – HJW Aug 22 '20 at 20:03

0 Answers0