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