开发者

Errors deleted in validation with valid? in Rails

I'm trying to create a form validation.

I added @user.errors.add_to_base "TEST" to my controller, and if I call @user.valid?, i开发者_JAVA百科t returns false (yes, this is correct). But the error "TEST" isn't displayed (errors from the model, like from validates_presence_of, are).

Why does it 'delete' my error? How can I avoid it?


This behavior is correct. valid? method really cleans the errors array. The problem is in the way you are using it. Is there any reason why do you generate errors in the controller? This should be the business of model validation and it's one of the main responsibilities of a model. Maybe if you provided us with some more code, so we could figure out what went wrong?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜