Reputation: 124
I need to validate that the value of a field (:discount) is one of an array of strings. The :discount field can also be blank UNLESS the :type field is 'FixedDeal' (STI)
validates :discount, inclusion: {in: VALID_DISCOUNTS}, allow_blank: true unless :type == 'FixedDeal'
The above code works to validation the value of :discount, but allows the field to be blank even if the type is 'FixedDeal'.
Upvotes: 0
Views: 276
Reputation: 571
On your FixedDeal class add the following validation:
validates_presence_of :discount
That should work for you.
Upvotes: 1