I have an Order model with two virtual attributes for account number
and sort code for setting up a recurring bank payment (Direct Debit in
the UK). I do not want to save the account details in my database
(similar to the reason for credit card numbers) but obviously collect
the details through a form.
I have tried this:
validates_numericality_of :dd_account, :only_integer => true
validates_length_of :dd_account, :is => 8, :wrong_length =>
"^Account number|Must be 8 digits long"
but I get the following exception:
which I suspect is that this type of validation will not work with
virtual attributes. Is this the case???
Is the approach below the best solution or even work?
errors.add(:dd_account, "Some error message") if detect_something
Additionally, can you use the class methods in custom methods? I
would like to use validates_length_of etc if I go down the custom
method route. Again, if I do manage to use them will they work on