When i used the following piece of code in my model it worked fine for creating a new entry but when i tried to edit the form i am getting the same error message, which is showing for creating a new one. Actual problem is that when i edit the same form entry for the same data it shouldn't to give that error. It should give the error message only when duplicate data is created with following validated fields.
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