我正在尝试设置 Rails Administrate - https://github.com/thoughtbot/administrate。
遵循文档:
gem "administrate"
在里面Gemfile
rails generate administrate:install
- “重新启动您的服务器,然后访问 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
现在它起作用了!