ruby on rails - Validate presence of one field or another (XOR) -


How do I accept the presence of a field or another, but at least one and at least one?

If you add conditional to numerical assumptions, your code will work:

  class transaction and lieutenant; ActiveRecord :: Base validates_presence_of: date validates_presence_of: name validates_numericality_of: fee, allow_nil: true validates_numericality_of: payment, allow_nil: true valid: charge_xor_payment private def charge_xor_payment until charging. ^ Payment.blank? Errors.add (: Base, "Specify a charge or payment, not both,") End end term  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -