Assuming you start with your model Thingusing an unencrypted attribute note.
1) Add a transition to add a field encrypted_noteand fill it
class EncryptThing < ActiveRecord::Migration
def up
rename_column :things, :note, :old_note
add_column :things, :encrypted_note, :string
Thing.find_each do |t|
t.note = t.old_note
t.save
end
remove_column :things, :old_note
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
2) Add a line to your model to specify an encrypted attribute:
attr_encrypted :note, :key => Rails.application.config.key
3) start the migration
rake db:migrate
source
share