ambition/app/models/mission.rb

34 lines
891 B
Ruby
Raw Normal View History

2016-12-26 12:13:59 +08:00
class Mission < ActiveRecord:: Base
2016-12-27 20:15:05 +08:00
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
2016-12-26 12:13:59 +08:00
end