I set these methods to automatically encrypt values.
class User < ApplicationRecord
def name=(val)
super val.encrypt
end
def name
(super()
Why are you exposing it as name at all ?
class User < ApplicationRecord
def decrypted_name=(val)
name = val.encrypt
end
def decrypted_name
name.decrypt
end
end
Then you use @model.decrypted_name
instead of @model.name
as name is encrypted, and such saved in DB.
edit.haml
=@user.decrypted_name
=form_for @user, html: { multipart: true } do |f|
=f.text_field :decrypted_name
And name
if it is encrypted should not be handled directly but with this decrypted_name
accessor.