开发者

Tire search and will_paginate - undefined method `offset'

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜