我有一张名为 items 的表。我想更改 9 个对象的描述属性(它是一个文本属性)。具体来说,这些对象是 Item 的子类——称为 Juice。所以项目表是 STI。这是该项目的示例描述:
将所有支出提高20%。
现在,当我尝试运行以下迁移时,我无法更新该当的描述。有任何想法吗?(Rails 版本是 2.3.11。)
class ModifyItemJuiceDescription < ActiveRecord::Migration
def self.up
juices = Juice.all
Juice.transaction do
for j in juices do
puts "Juice description is: #{j.description}."
j.description.gsub!('payouts', 'winnings')
puts "Juice description will be saved as: #{j.description}."
j.save!
puts "Juice description is now: #{j.description}."
puts "======================================================"
end
end
end
def self.down
juices = Juice.all
Juice.transaction do
for j in juices do
puts "Juice description is: #{j.description}."
j.description.gsub!('winnings', 'payouts')
puts "Juice description will be saved as: #{j.description}."
j.save!
puts "Juice description is now: #{j.description}."
puts "======================================================"
end
end
end
end