Sha256: 370e5c5e4f9e277dfd1e8b4a589f10d8c649f6ec971a614c12211a85476d2be9

Contents?: true

Size: 633 Bytes

Versions: 5

Compression:

Stored size: 633 Bytes

Contents

module FinePrint
  class Signature < ActiveRecord::Base
    belongs_to :contract, :inverse_of => :signatures
    belongs_to :user, :polymorphic => true

    before_create :contract_published

    validates_presence_of :contract, :user_type, :user_id
    validates_uniqueness_of :contract_id, :scope => [:user_type, :user_id]

    default_scope order(:contract_id, :user_type, :user_id)

    protected

    ##############
    # Validation #
    ##############

    def contract_published
      return if contract.is_published?
      errors.add(:contract, 'needs to be published before it can be signed')
      false
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fine_print-1.3.0 app/models/fine_print/signature.rb
fine_print-1.2.0 app/models/fine_print/signature.rb
fine_print-1.1.1 app/models/fine_print/signature.rb
fine_print-1.1.0 app/models/fine_print/signature.rb
fine_print-1.0.0 app/models/fine_print/signature.rb