Skip to content

Instantly share code, notes, and snippets.

@kirs
Last active November 22, 2016 21:26
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 kirs/b98e912261d27f97827cbf13b0c163c7 to your computer and use it in GitHub Desktop.
Save kirs/b98e912261d27f97827cbf13b0c163c7 to your computer and use it in GitHub Desktop.

Legacy Database

User.first.name # => "Renan"

After put encrypted_coder.rb and crypt.rb

User.first.name # => OpenSSL::Cipher::CipherError: bad decrypt

The error above is because the value of column name into dabase already exists and has the value renan, so who could I fix this :x


You'll need to update all records:

User.find_each do |user|
  user.name = user.attributes['name']
  user.save!
end

As a result all users will get new encrypted values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment