Reputation: 740
I need to convert values stored in my Rails 3.0 application's database table from pounds to kilograms. This is a one-time task.
Is this something I could do from the console? If so, how? The values are stored in my weights table in the weight_entry column.
I know it should look something like:
Weights.each do |weight|
weight.weight_entry = weight.weight_entry * 0.45
weight.save
end
I don't know how to initialize the Weights constant though.
Thanks for you help!
Upvotes: 0
Views: 3934
Reputation: 782
Try This
rails c
Weight.all.each{ |weight_obj| weight_obj.update_attributes(:weight_entry => (weight_obj.weight_entry * 0.45) ) }
Upvotes: 1