
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 0.57 KB | hits: 9 | expires: Never
Rails 3. before_destroy validation to prevent deleting parent records
has_one :invoice
before_destroy :check_for_invoice
private
def check_for_invoice
unless invoice.nil?
self.errors[:base] << "Cannot delete shipment while its invoice exists."
end
end
has_one :invoice
before_destroy :check_for_invoice
private
def check_for_invoice
unless invoice.nil?
self.errors[:base] << "Cannot delete shipment while its invoice exists."
return false
end
end
self.errors[:base] << "Cannot delete shipment while its invoice exists." and return false