Skip to content

Instantly share code, notes, and snippets.

@neilmarion
Last active April 27, 2017 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilmarion/e49d5c3247ae37f648391a3465abbfcc to your computer and use it in GitHub Desktop.
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
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