Sha256: e36ab98ff31c1b6b63ad326b6d334982eb45be3e36e71e3536c4c52725ffbab0
Contents?: true
Size: 821 Bytes
Versions: 5
Compression:
Stored size: 821 Bytes
Contents
module InvoiceBar class InvoiceTemplate < ActiveRecord::Base before_validation :update_amount attr_accessible :name validates :name, presence: true validate :name_is_unique include InvoiceBar::Billable::Base include InvoiceBar::Billable::Invoicing include InvoiceBar::Billable::Associations::Base delegate :name, :tax_id, :address, to: :user, prefix: true # Search include InvoiceBar::Searchable def self.searchable_fields %w( name ) end private # Validates uniqueness of a name for current user. def name_is_unique invoice_templates = InvoiceTemplate.where(name: name, user_id: user_id) if invoice_templates.any? && !invoice_templates.include?(self) errors.add(:name, :uniqueness) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems