使用 meta_search 进行列排序时出现 Kaminari 问题
我正在使用 Kaminari 进行分页,并尝试使用 meta_search 进行列排序。我希望我的代码看起来像这样:
@search = Organization.search(params[:search])
@organizations = @search.page(params[:page])
当我这样编写时,我收到错误,
undefined method `page' for #<MetaSearch::Builder:0x7fadb8958630>
我找到的解决方案是这样的:
@search = Organization.search(params[:search])
@organizations = Kaminari.paginate_array(@search.all).page(params[:page]
它可以工作,但感觉很笨重。我发现的所有示例都表明第一个示例应该可以开箱即用。有什么方法可以将 MetaSearch 结果转换为 ActiveRecord 兼容对象吗?
I am using Kaminari for pagination and trying to use meta_search for column ordering. I would like my code to look like this:
@search = Organization.search(params[:search])
@organizations = @search.page(params[:page])
When I write it this way, I am getting the error,
undefined method `page' for #<MetaSearch::Builder:0x7fadb8958630>
The solution I have found is this:
@search = Organization.search(params[:search])
@organizations = Kaminari.paginate_array(@search.all).page(params[:page]
It works but feels clunky. All the examples I have found suggest the first example should work out of the box. Is there any way to turn the MetaSearch result into an ActiveRecord compatible object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试更新版本的meta_search +1.0,它提供与Kaminari 的集成。
Try a newer version of meta_search +1.0 it provides integration with Kaminari.