Sha256: 92c180dca5942d185cf1e4a069c7caf90f40e49ad8f9d400efb199b621ca891b

Contents?: true

Size: 828 Bytes

Versions: 8

Compression:

Stored size: 828 Bytes

Contents

class Candidature < ActiveRecord::Base
  include StateMachines::Candidature
  
  belongs_to :vacancy
  belongs_to :offeror, class_name: 'User'
  belongs_to :user

  has_many :comments, as: :commentable, dependent: :destroy

  scope :accepted, where(state: 'accepted')

  validates :vacancy_id, presence: true
  validates :offeror_id, presence: true
  validates :user_id, presence: true, uniqueness: { scope: :vacancy_id }
  #validates :name, presence: true, uniqueness: { scope: :vacancy_id }
  validates :text, presence: true
  
  attr_accessible :vacancy_id, :name, :text
  
  #extend FriendlyId
  #friendly_id :name, use: :slugged
  
  before_validation :set_offeror
  
  # association shortcuts
  def project
    vacancy.project
  end
  
  private
  
  def set_offeror
    self.offeror_id = vacancy.project.user_id
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
voluntary-0.1.0 app/models/candidature.rb
voluntary-0.1.0.rc4 app/models/candidature.rb
voluntary-0.1.0.rc3 app/models/candidature.rb
voluntary-0.1.0.rc2 app/models/candidature.rb
voluntary-0.1.0.rc1 app/models/candidature.rb
voluntary-0.0.3 app/models/candidature.rb
voluntary-0.0.2 app/models/candidature.rb
voluntary-0.0.1 app/models/candidature.rb