socialforge/app/models/biding_project.rb

46 lines
1.1 KiB
Ruby
Raw Normal View History

2013-08-04 10:59:25 +08:00
## fq
2013-08-01 10:33:49 +08:00
class BidingProject < ActiveRecord::Base
attr_accessible :bid_id, :project_id, :user_id, :description
belongs_to :bid
belongs_to :project
belongs_to :user
DESCRIPTION_LENGTH_LIMIT = 500
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
validates_presence_of :user_id, :bid_id, :project_id
validate :validate_user
validate :validate_bid
validate :validate_project
validates_uniqueness_of :bid_id, :scope => :project_id
def self.cerate_bidding(bid_id, project_id, description = nil)
self.create(:user_id => User.current.id, :bid_id => bid_id,
:project_id => project_id, :description => description)
end
def cancel_bidding
unless self.nil?
if User.current.id == self.user_id
self.destroy
end
end
end
private
def validate_user
errors.add :user_id, :invalid if user.nil? || !user.active?
end
def validate_bid
errors.add :bid_id, :invalid if bid.nil?
end
def validate_project
errors.add :project_id, :invalid if project.nil?
end
end