简体   繁体   English

当我在Gemfile中包含ransack gem时,Thinking_sphinx搜索方法不起作用

[英]Thinking_sphinx Search method doesn't work when I include ransack gem in my Gemfile

I included thinking_sphinx gem in my project. 我在我的项目中包含了think_sphinx gem。

Article.search "Bla-bla-bla" works fine. Article.search "Bla-bla-bla"效果很好。

But when I include ransack gem in my Gemfile I get the error: 但是,当我在Gemfile中包含ransack gem时,会出现错误:

NoMethodError: undefined method `with_indifferent_access' for "Bla-bla-bla":String from /Users/ashvalev/.rvm/gems/ruby-1.9.2-p290/gems/ransack-0.7.2/lib/ransack/search.rb:21:in `initialize'

It is because ransack gem also uses name "search" for its searching method. 这是因为ransack gem还使用名称“ search”作为其搜索方法。

What can I do to make these gems work together? 我该怎么做才能使这些宝石一起工作?

The solution is to call ThinkingSphinx.search instead of the specific model's #search method. 解决方案是调用ThinkingSphinx.search而不是特定模型的#search方法。

Instead of 代替

Article.search "Bla-bla-blah"

Use the system-wide search call, but constrain to the class... 使用系统范围内的搜索调用,但仅限于该类...

ThinkingSphinx.search "Bla-Bla-Blah", classes: [Article]

You'll want to list ransack before thinking-sphinx in your Gemfile - the load order matters. 您需要在Gemfile中的思想狮身人面像之前列出ransack-加载顺序很重要。

Though I would certainly recommend just using one of the two when it comes to searches. 尽管我当然会建议在搜索时仅使用两者之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM