Jaydip Pansuriya
Jaydip Pansuriya

Reputation: 214

errors went out after saving object in rails

When I add errors in object and save it. I lost those errors which I added. Ex :

@student.errors.add(:base,"error added " )

@student.save

@student.errors.size ---> 0  

Please eneyone can say why this is happening?

Upvotes: 0

Views: 604

Answers (1)

Sachin Singh
Sachin Singh

Reputation: 1098

Why do you need to save the object after adding the error? The errors are either added through model validations or we add them through some custom logic. The object is not saved in both cases. If you save the object, you would lose the errors.

Upvotes: 1

Related Questions