当前位置 : 主页 > 编程语言 > ruby >

ruby-on-rails – 用简单的形式显示完整的错误消息?

来源:互联网 收集:自由互联 发布时间:2021-06-23
如何使用简单形式输出字段的完整错误消息?相当于rails:%= RESOURCE.errors.full_messages% 例如显示这个: "Email has already been taken", "Password confirmation doesn't match Password", "Password is too short
如何使用简单形式输出字段的完整错误消息?相当于rails:<%= RESOURCE.errors.full_messages%>

例如显示这个:

"Email has already been taken", 
"Password confirmation doesn't match Password", 
"Password is too short (minimum is 8 characters)"

而不是:f.error_notification

"has already been taken", 
"doesn't match Password", 
"is too short (minimum is 8 characters)"

simple_form(3.0.2)/ Rails 4.1.1

如果有人仍然想知道现在有一种简单的方法可以做到这一点,参考 here

只需在config / initializers / simple_form.rb下,将b.user:error更改为b.user:full_error,现在您的错误消息将等同于RESOURCE.errors.full_messages

注意:如果您使用的是带简单表单的bootstrap,则更改simple_form_bootstrap.rb

网友评论