-1
当我在我的模型中使用下面的一段代码时,它可以很好地创建一个新的条目,但是当我试图编辑表单时,我得到了相同的错误消息,这是显示创建一个新的。实际的问题是,当我编辑相同的数据相同的表单条目,它不应该给这个错误。只有在创建具有以下验证字段的重复数据时,它才会给出错误消息。验证在导轨2中编辑表单时发生错误?
module StudentModel
validate :is_valid_true
private
def is_valid_true
@batch = Batch.find(self.batch_id)
@batch.students.each do |s|
if ((s.full_name==self.full_name)&&(s.phone2==self.phone2))
errors.add_to_base("Student with same Name and Mobile number is already Present in the Batch")
break
end
end
end
end