rails - 让model显示validation错误信息

访问量: 366

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"]}

订阅/RSS Feed

Subscribe