Created
November 6, 2012 10:55
-
-
Save ariejan/4024019 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BankAccount < ActiveRecord::Base | |
include AttributeEncryption | |
belongs_to :billable, polymorphic: true | |
encrypted_attribute :encrypted_number, hash: true | |
validates :number, | |
format: { with: /[pP]?\d*/ } | |
# encrypted_attribute overrides #number= in order | |
# to perform some encryption magic, hence a | |
# before_validation hook does not work to strip | |
# the account number from unwanted characters. | |
alias_method :orig_number=, :number= | |
def number=(value) | |
value = value.gsub(/[ -\.]/, '') unless value.nil? | |
send(:orig_number=, value) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment