我需要使用 Ransack,我安装了 gem,我重新启动了我的服务器,我在我的 Controller 中写了这个:
def index
@q = Sound.search(params[:q]) @sounds = @q.result
end
在我看来:
<%= f.label :title_cont %> <%= f.text_field :title_cont %> <%= f.submit "Search" %>
但是我有这个错误:
#ActiveRecord::Relation:0x007fa185e9c2c0 的未定义方法“结果”>
我试图找到答案,但都不起作用。
谢谢你的帮助
编辑: 我找到了我的解决方案,我使用了另一个 gem:Sunspot 和那个工作。
谢谢大家的帮助。
最佳答案
我刚遇到同样的问题。
我在这里找到了解决方案 https://github.com/activerecord-hackery/ransack/issues/266
我变了
@q = Sound.search(params[:q])
@sounds = @q.result
到
@q = Sound.ransack(params[:q])
@sounds = @q.result
我认为 ActiveAdmin 已经覆盖了我的搜索方法,因此,正如上面链接中所解释的,已经创建了 ransack 方法来运行搜索,以防另一个 gem 使用“搜索”。
关于ruby-on-rails - 洗劫 : Undefined Method "result",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19227019/