ambition/app/models/mission.rb

34 lines
891 B
Ruby

class Mission < ActiveRecord:: Base
has_many :comments
validates :name, presence: true
validates :deadline, presence: true
validates :priority, presence: true
validates :status, presence: true
validates :content, presence: true
validate :priority_is_among_valid_values
validate :status_is_among_valid_values
private
def priority_is_among_valid_values
if priority != 1 and priority != 2 and priority != 3
errors[:priority] = "priority is not among valid values"
end
end
def status_is_among_valid_values
values = ["未开始","进行中","已完成","已测试"]
if !values.include?(status)
errors[:status] = "status is not among valid values"
end
end
end