Topic: AR validation
What is the best way to implement a validation for a withdrawal operation? So there is an Operation and Client models.
Client has_many :operations. In case of withdrawal operation, I'd like to check if the requested sum is not greater than a Client account balance. How to link the validation in the Operation model to a specific client ? I tried scope, before save, etc, nothing works as needed.
class Client < AR
has_many :operations
end
class Operation < AR
belongs_to :client
attr_accessible :sum
endIn fact, the validation should be done only in case of withdrawal operation type defined as a constant value in the model Operation.
The routes are defined so that an operation could only created in the context of a Client (as nested route).
Thanks
Last edited by Javix (2012-10-12 17:20:14)