在Soulmate :: Loader中添加两个参数

时间:2015-02-24 05:22:19

标签: ruby-on-rails redis

我的模型中有两个字段,我想在Soulmate :: Loader中添加它们:

例如,我的"人" model有姓名和电子邮件字段。然后我想在Soulmate中加载:

loader = Soulmate::Loader.new("people")
    loader.add("term" => name, "id" => self.id, "data" => {
        "link" => Rails.application.routes.url_helpers.person_path(self)
    }) 

我想在loader.add中添加nameemail。但我不能。

def load_into_soulmate
    loader = Soulmate::Loader.new("people")
    loader.add("term" =>{ name , email }, "id" => self.id, "data" => {
        "link" => Rails.application.routes.url_helpers.person_path(self)
    })
end

def load_into_soulmate
    loader = Soulmate::Loader.new("people")
    loader.add("term" =>{ "name" => name ,"email" =>  email }, "id" => self.id, "data" => {
        "link" => Rails.application.routes.url_helpers.person_path(self)
    })
end
当我使用Person.find_each(&:save)为redis添加数据时出现

错误:

ArgumentError: ArgumentError
from /var/lib/gems/2.2.0/gems/soulmate-1.1.0/lib/soulmate/loader.rb:31:in `add'

但一切都错了。

1 个答案:

答案 0 :(得分:0)

我认为你必须使用别名。

def load_into_soulmate
    loader = Soulmate::Loader.new("people")
    loader.add("term" =>"name", "id" => self.id, "aliases" => [email], "data" => {
        "link" => Rails.application.routes.url_helpers.person_path(self)
    })
end