轮胎搜索和will_paginate - 未定义的方法`offset' [英] Tire search and will_paginate - undefined method `offset'

查看:140
本文介绍了轮胎搜索和will_paginate - 未定义的方法`offset'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在ThinkingSphinx和Solr / Sunspot头痛之后,我们正在尝试ElasticSearch和Tire作为我们的搜索后端。这是控制器中的搜索命令:

  @results = Item.search params [:search],:page => (params [:page] || 1),:per_page => 20 

这是视图的问题部分:

 <%= page_entries_info @results%> 

我收到的错误消息是



< #p $ p> undefined方法#< Tire :: Results :: Collection:0xa3f01b0>

,但只有当有多个页面的结果值。如果返回的项目少于20个,那么他们会被罚款。



我可以在别处找到的唯一类似的报告问题是通过传递:per_page 参数到搜索函数,但我已经在做

解决方案

轮胎有分页模块,但是它没有定义 offset 。你可以提出一个问题来添加它,但同时你可以在你的应用程序中修改它:

 轮胎::结果:: Pagination.module_eval do 
def offset
(@options [:per_page] || @options [:size] || 10).to_i *(current_page - 1)
end
end


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

这篇关于轮胎搜索和will_paginate - 未定义的方法`offset'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆