30 lines
745 B
Ruby
30 lines
745 B
Ruby
class Comment < ActiveRecord:: Base
|
|
|
|
belongs_to :mission
|
|
validates :content, presence: true
|
|
validates :mission_id, presence: true
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
def comment_has_atleast_one_character
|
|
tmp = content.strip
|
|
if tmp.length < 1
|
|
errors[:content] = 'content should has at least one character'
|
|
end
|
|
end
|
|
|
|
# mission 是否存在的验证将放在controller中进行
|
|
|
|
# def mission_id_should_be_exist
|
|
|
|
# @mission = Mission.find(:mission_id)
|
|
|
|
# if @mission == nil
|
|
# errors[:mission_id] = "mission is not exist"
|
|
# end
|
|
# end
|
|
|
|
end |