Home Rails 让model显示validation错误信息
Post
Cancel

Rails 让model显示validation错误信息

refer to: https://stackoverflow.com/questions/31806431/rails-validation-knowing-which-field-is-invalid

product.valid? # => run validation callbacks, 这个方法一定要调用,否则不会展示下面的内容

product.errors.messages # => {:field1=>["cannot be nil"]}

This post is licensed under CC BY 4.0 by the author.