Allow updating currency of ticket if its the only ticket

This commit is contained in:
Nishanth Vijayan 2016-05-28 20:57:25 +05:30
parent efda31870b
commit 69f4771ec6
2 changed files with 6 additions and 0 deletions

View file

@ -59,6 +59,7 @@ class Ticket < ActiveRecord::Base
private
def tickets_of_conference_have_same_currency
return if self.persisted? && Ticket.where(conference_id: conference_id).count == 1
unless Ticket.where(conference_id: conference_id).all?{|t| t.price_currency == self.price_currency }
errors.add(:price_currency, 'is different from the existing tickets of this conference.')
end