[英]How to manage errors with simple_form in rails 6
I have a form where I have added some validation, I would like the errors to be listed, I have an idea that it can be done this way.我有一个表格,我在其中添加了一些验证,我希望列出错误,我知道可以通过这种方式完成。
= simple_form_for(@post) do |f|
.row.pt-4
.col-lg-3
-if f.object.errors[:base].present?
.alert.alert-danger
%ul
%li= f.error_notification message: f.object.errors[:base].to_sentence
The problem I have is that the first error is listing it correctly, but the others are not.我遇到的问题是第一个错误是正确列出它,但其他错误不是。
example with more errors有更多错误的例子
it should be displayed every error with a bullet point它应该用项目符号显示每个错误
You need to loop over the errors:您需要遍历错误:
= simple_form_for(@post) do |f|
.row.pt-4
.col-lg-3
-if f.object.errors.any?
.alert.alert-danger
%ul
= f.object.errors.each do |error|
%li= f.error_notification message: error.message
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.