문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top