1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/models/coupon.rb
2016-08-08 12:25:27 +02:00

19 lines
411 B
Ruby

class Coupon < ActiveRecord::Base
has_many :invoices
validates :name, presence: true
validates :code, presence: true
validates :code, format: { with: /\A[A-Z0-9]+\z/ ,message: 'only caps letters and numbers'}
validates :percent_off, presence: true
validates :percent_off, :inclusion => 0..100
def safe_destroy
if self.invoices.size == 0
destroy
else
false
end
end
end