I have a model Order
with the price
attribute.
There are few Order
records in the database without a price
attribute(nil
value) which was imported from the old database. There are less than 20 invalid records like this.
Now the price
attribute is mandatory.
I need to add a presence validation of the price
and preserve the old records.
I can't set the nil
values to zero or some random values.
I have some crazy ideas about the conditional validation on the basis of the timestamp or even a list of "permitted" ids.
Something like this:
PERMITTED_IDS = [4, 8, 15, 16, 23, 42]
validates :price, presence: true, if: -> { |order| PERMITTED_IDS.exclude?(order.id) }
Is there any nice and convenient way for that?