Last active
April 27, 2017 03:22
-
-
Save neilmarion/e49d5c3247ae37f648391a3465abbfcc to your computer and use it in GitHub Desktop.
Number one rule to updating fields of database rows via Rails migration is to first check if they are existing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UpdateAddressOfASchool < ActiveRecord::Migration | |
def up | |
['Ateneo', 'UP'].each do |name| | |
school = School.where(name: name).first | |
if school | |
school.update_attributes(address: "Quezon City") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment