【问题标题】:Rails, Octopus, access variable in master defined in slave?Rails,Octopus,在slave中定义的master中的访问变量?
【发布时间】:2017-07-03 07:41:37
【问题描述】:

我想访问主范围内的 slave1 范围内定义的变量。如何正确确定变量的范围,使其在从块中设置并在主块中可用?

Octopus.using(:slave1) do
  locations_with_wrong_country_code_ids = Location.where(country: "USA").ids
end

Octopus.using(:master) do
  Location.where(id: locations_with_wrong_country_code_ids).each do |location|
    location.country = "US"
    location.save
  end  
end

【问题讨论】:

    标签: ruby-on-rails variables scope octopus


    【解决方案1】:

    这样做:

    locations_with_wrong_country_code_ids = Octopus.using(:slave1) do
      Location.where(country: "USA").ids
    end
    
    Octopus.using(:master) do
      Location.where(id: locations_with_wrong_country_code_ids).each do |location|
        location.country = "US"
        location.save
      end  
    end
    

    【讨论】:

      猜你喜欢
      • 2017-06-02
      • 1970-01-01
      • 2013-11-27
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      • 2016-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多