Changed minutes to hours for target/program

This commit is contained in:
Shayon Mukherjee 2015-03-16 16:12:16 -07:00
parent ff124632ef
commit 5efe8d8862
5 changed files with 38 additions and 17 deletions

View file

@ -0,0 +1,22 @@
class ConvertTargetMinutesToHours < ActiveRecord::Migration
class TempTarget < ActiveRecord::Base
self.table_name = 'targets'
attr_accessible :target_count, :unit
end
def up
targets = TempTarget.where(unit: 'Program minute').where.not(target_count: nil)
targets.each do |target|
new_target_count = (target.target_count / 60.to_f).round
target.update_attributes(target_count: new_target_count, unit: 'Program hours')
end
end
def down
targets = TempTarget.where(unit: 'Program hours').where.not(target_count: nil)
targets.each do |target|
new_target_count = (target.target_count * 60.to_f).round
target.update_attributes(target_count: new_target_count, unit: 'Program minute')
end
end
end