轮胎搜索和 will_paginate - 未定义的方法“offset”
在经历了 ThinkingSphinx 和 Solr/Sunspot 的头痛之后,我们正在尝试使用 ElasticSearch 和 Tire 作为我们的搜索后端 - 但我遇到了一个问题。
这是我在控制器中的搜索命令:
@results = Item.search params[:search], :page => ( params[:page] || 1 ), :per_page => 20
这是视图的问题部分:
<%= page_entries_info @results %>
我收到的错误消息是
undefined method `offset' for #<Tire::Results::Collection:0xa3f01b0>
但仅当有超过一页的结果时。如果返回的商品少于 20 件,则显示正常。
我在其他地方找到的唯一类似的报告问题是通过将 :page
和 :per_page
参数传递到 search
函数中解决的,但我已经这样做了,但无济于事。
After headaches with ThinkingSphinx and Solr/Sunspot, we're trying out ElasticSearch and Tire as our search back-end - but I've hit a problem.
Here's my search command in the controller:
@results = Item.search params[:search], :page => ( params[:page] || 1 ), :per_page => 20
And this is the problem section of the view:
<%= page_entries_info @results %>
The error message I'm getting is
undefined method `offset' for #<Tire::Results::Collection:0xa3f01b0>
but only when there is more than one page's worth of results. If there are less than 20 items returned, then they get shown fine.
The only similar reported issue I could find elsewhere was solved by passing the :page
and :per_page
parameters into the search
function, but I'm already doing that, to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Tire 有分页模块,但它没有t 定义偏移量。您可以向他们提出问题来添加它,但同时您可以在您的应用程序中对其进行猴子修补:
Tire has a Pagination module but it doesn't define
offset
. You could file an issue with them to add it, but in the meantime you can monkeypatch it in your app:在我的测试应用程序中,结果分页得很好,使用
will_paginate 3.0
和tire 0.3
。我不知道 will_paginate 需要offset
方法。不过,我已经添加了它,复制了
will_paginate
规范中的“lint”测试:https://github.com/karmi/tire/commit/e0e7730。应该是下一个版本的一部分。in my testapp, results are paginated just fine, with
will_paginate 3.0
andtire 0.3
. I wasn't aware will_paginate needed theoffset
method.I've added it, however, copying over the "lint" test from
will_paginate
specs: https://github.com/karmi/tire/commit/e0e7730. Should be part of the next release.