Rails Kaminari 分页和存储过程
我有 2 个存储过程,它们返回带有限制、偏移量以及所有记录计数的数据。 在这种情况下如何使用 Kaminari 进行分页?
UPD 我在 Edge 版本中遇到了 Kaminari 问题!我有从 ActiveRecord 扩展的抽象类 MyRecord,其他模型扩展了这个抽象类。
class Customer < MyRecord
has_one :active_order, :class_name => 'Order',
:conditions => {
:status_type => [Order::STATUS_TYPES[:active],Order::STATUS_TYPES[:paused]]
}
......
控制器
@customers = Customer.search(params[:search]).includes(:active_order).order(sort_column + ' ' + sort_direction).page(params[:page]).per(25)
我现在得到错误的查询(抽象类表名称而不是模型表名称)
SELECT `my_records`.* FROM `my_records` WHERE
(`my_records`.customer_id IN (160,161,162,163,164,165,166,167,168,169,170)
AND (`my_records`.`status_type` IN (0, 2)))
I have 2 stored procedures wich return data with limit and offset and count of all records.
How can I use Kaminari for pagination in this case ?
UPD
I have problem with kaminari in edge version! I have abstract class MyRecord extended from ActiveRecord, other models extends this abstract class.
class Customer < MyRecord
has_one :active_order, :class_name => 'Order',
:conditions => {
:status_type => [Order::STATUS_TYPES[:active],Order::STATUS_TYPES[:paused]]
}
.......
controller
@customers = Customer.search(params[:search]).includes(:active_order).order(sort_column + ' ' + sort_direction).page(params[:page]).per(25)
I get now wrong query (abstract class table name instead of model table name)
SELECT `my_records`.* FROM `my_records` WHERE
(`my_records`.customer_id IN (160,161,162,163,164,165,166,167,168,169,170)
AND (`my_records`.`status_type` IN (0, 2)))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚在 Kaminari::PaginatableArray 上添加了一个新功能,可以解决您的问题。
https://github.com/amatsuda/kaminari/pull/141
你可以捆绑Kaminari 的边缘版本:
并像这样将
:total_count
选项传递给PaginatableArray#new
?或者
Just added a new feature on Kaminari::PaginatableArray that would solve your problem.
https://github.com/amatsuda/kaminari/pull/141
Can you bundle the edge version of Kaminari:
and pass
:total_count
option toPaginatableArray#new
like this?or