TypeError:无法将Array转换为Hash

时间:2013-09-24 02:29:03

标签: ruby-on-rails ruby-on-rails-3 elasticsearch tire

我似乎无法弄清楚为什么我收到以下错误:

can't convert Array into Hash

这是应用程序跟踪:

app/models/channel.rb:21:in `search'
app/controllers/posts_controller.rb:107:in `browse'

以下代码来自channel.rb(在应用程序跟踪中引用),其中第21行是“tire.search ...”:

def self.search(params)
  tire.search(['posts_index', 'channels_index'],{load: true}) do
    query { string params[:query], default_operator: "AND" } if params[:query].present? 
    sort { by :created_at, "desc" } if params[:query].blank?
  end
end

我还包括了posts_controller.rb的浏览操作,也在上面的跟踪中引用:

def browse
    @user = current_user
    @channels = Channel.search(params)
    @posts = Post.search(params)
end

我的目标是使用Tire / ElasticSearch搜索多个索引。任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:0)

嘿尝试添加“ load:true ”而不提供花括号。它对我有用......

def self.search(params)
  tire.search(['posts_index', 'channels_index'],load: true) do
    query { string params[:query], default_operator: "AND" } if params[:query].present? 
    sort { by :created_at, "desc" } if params[:query].blank?
  end
end

答案 1 :(得分:0)

我最后对这个问题的描述有所不同 - 并且能够解决它。请参阅:Search multiple models with Tire and ElasticSearch