Changed minutes to hours for target/program
This commit is contained in:
parent
ff124632ef
commit
5efe8d8862
5 changed files with 38 additions and 17 deletions
22
db/migrate/20150317210343_convert_target_minutes_to_hours.rb
Normal file
22
db/migrate/20150317210343_convert_target_minutes_to_hours.rb
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue