class ApplyResource < ActiveRecord::Base
  # status：1. 等待回复 2.审核通过 3.已拒绝
  attr_accessible :attachment_id, :status, :user_id, :container_type, :container_id, :apply_user_id, :content
  belongs_to :user
  belongs_to :attachment
  has_many :course_messages, :class_name => 'CourseMessage', :as => :course_message, :dependent => :destroy
  after_create :act_as_apply_resource_message

  def act_as_apply_resource_message
    self.course_messages << CourseMessage.new(:user_id => self.apply_user_id, :course_id => -1, :viewed => false, :status => 0, )
    # REDO:发送邮件
    # Mailer.run.apply_for_resource_request(self.container_id, User.current)
  end

  def find_attachment attachment_id
    Attachment.find(attachment_id)
  end

end
