轮胎搜索和 will_paginate - 未定义的方法“offset”

发布于 2024-12-02 17:49:21 字数 615 浏览 1 评论 0原文

在经历了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提笔书几行 2024-12-09 17:49:21

Tire 有分页模块,但它没有t 定义偏移量。您可以向他们提出问题来添加它,但同时您可以在您的应用程序中对其进行猴子修补:

Tire::Results::Pagination.module_eval do
  def offset
    (@options[:per_page] || @options[:size] || 10 ).to_i * (current_page - 1)
  end
end

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:

Tire::Results::Pagination.module_eval do
  def offset
    (@options[:per_page] || @options[:size] || 10 ).to_i * (current_page - 1)
  end
end
二货你真萌 2024-12-09 17:49:21

在我的测试应用程序中,结果分页得很好,使用 will_paginate 3.0tire 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 and tire 0.3. I wasn't aware will_paginate needed the offset 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文