attr_encrypted is a nice gem for encrypting fields in Rails.
You add this line to a model: attr_encrypted :field_name, key: ENV['attr_encrypted_key']
. I used rake secret
to generate that attr_encrypted_key
referenced in that line.
The field itself needs to be created in a particular way in the migration:
add_column :table_name, :encrypted_field_name, :text
add_column :table_name, :encrypted_field_name_iv, :text