I suggest something different.
Keep your obfuscated_ssn
method from your answer, it makes sense to have it in the model. However overriding the setter like this... well I'd go a different way.
What I don't really like, is that you are doing validations in the setter. I checked the gem page but couldn't find anything related to validation, but normally your model would include validation rules like
validates_length_of :ssn, :minimum => 5, :maximum => 20, :allow_blank => true
I don't know if the ssn gem is clever enough to run the validations only on non-encrypted data though...
But anyway here's how I would tweak your form/controller :
Your form
you would need to figure out how to display one field and submit to a completely different one
I suggest changing the default value shown by the field (Ruby doc for text_field :)
f.text_field(:ssn, :value => f.object.obfuscated_ssn)
Now I'm not sure about the behavior you want. Is the user supposed to always write the ssn field? Or do you want to leave it unchanged in case the user doesn't enter anything ? If so I'd put some checks on your controller
Controller
def model_params
if params[:your_model][:ssn] == @model.obfuscated_ssn
params[:your_model].delete(:ssn) # Make sure your model doesn't get updated with obfuscated ssn
end
params.require(:your_model).permit(:ssn, etc.)
end