0

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

1 回答 1

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-02-15T15:47:36.163 回答