i have encrypted attribute (let's call @model.encrypted_attribute) in 1 of models. before adding encryption had following validation in model:
validates_length_of :attribute, :minimum => 11, :maximum => 11, :allow_blank => true, :message => "| attribute must 11 digits long."
i had method ran before_save
gsub out non-numerical characters attribute. now, however, can't figure out how to:
- run
gsub!(/\d/, '')
on attribute before encrypted , saved or run afterwards , have attr-encrypted re-encrypt@model.attribute
value , write database. can strip characters, not re-encrypt/save. run validation on non-encrypted value of
attribute
before saving. have tried adding following code in before_block different error (undefined method '12345678' #<spree::order:0x007fae02011cd0
):def format_attribute validates_length_of self.attribute.gsub(/\d/, ''), :minimum => 9, :maximum => 9, :allow_blank => true, :message => "| attribute should 9 digits long." end
does have idea of how can achieve 1 or both of above or, @ least, set custom method run before attr_encrypted thing.
-------------edit-------------
leaving 2 above people come while searching solution can found @ validation of encrypted data
Comments
Post a Comment