0

我正在尝试设置 Rails Administrate - https://github.com/thoughtbot/administrate

遵循文档:

  1. gem "administrate"在里面Gemfile
  2. rails generate administrate:install
  3. “重新启动您的服务器,然后访问 http://localhost:3000/admin 以查看您的新仪表板正在运行。”

从 Rails 日志中,访问时localhost:3000/admin我看到执行了以下 SQL 查询:

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

为什么OFFSET放在475上?

但更重要的是,如何将其设置为 0 或完全删除它?

更新:

  • will_paginate也在使用(这里可能有冲突?)
  • 我的 Kaminari 设置在: 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

解决方案

will_paginate干扰了kaminari

我创建了一个初始化程序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

现在它起作用了!

4

0 回答 0