Rails,Octopus,在slave中定义的master中的访问变量?

时间:2017-02-14 20:49:35

标签: ruby-on-rails variables scope octopus

我想访问主范围内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

1 个答案:

答案 0 :(得分: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