小编Ale*_*der的帖子

使用Active Admin和Elastic Search时,Ransack :: Search的未定义方法`each'?

你好我一直在使用Railcasts#306(http://railscasts.com/episodes/306-elasticsearch-part-1)在我的应用程序中使用Elastic Search 作为示例.

在安装Active Admin gem之前,一切正常.当我在我的商店#index页面传递查询时,我收到以下错误:

未定义的方法`每个'用于Ransack :: Search>:Ransack :: Search

任何想法为什么它使用Ransack宝石(不是弹性搜索)进行搜索?

以下是与搜索相关的代码片段:

Shop.rb:

class Shop < ActiveRecord::Base

  include Tire::Model::Search
  include Tire::Model::Callbacks

  (...)

  end
Run Code Online (Sandbox Code Playgroud)

shops_controller.rb

  def index
    if params[:query].present?
      @shops = Shop.search(params[:query], load:true)
    else
      @shops = Shop.all
    end
    respond_with(@shops)
  end
Run Code Online (Sandbox Code Playgroud)

商店/ index.html.erb

<%=form_tag shops_path, :method =>:get do %>
<p><%= text_field_tag :query, params[:query] %>
<%= submit_tag "Search", :name => nil, class: "button small success" %></p>
<% end %>
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,谢谢!

ruby ruby-on-rails elasticsearch activeadmin ruby-on-rails-4

3
推荐指数
1
解决办法
1332
查看次数