以简单的形式显示完整的错误消息? [英] Show full error messages with simple form?
问题描述
如何使用简单的表单输出字段的完整错误信息?相当于rails:<%= RESOURCE.errors.full_messages %>
How do I output the full error message of a field using simple form? The equivalent of 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
推荐答案
如果有人仍然想知道现在有一种简单的方法可以做到这一点,参考 这里
If anyone is still wondering there is an easy way to do this now, as referenced here
只需在 config/initializers/simple_form.rb
下将 b.user :error
更改为 b.user :full_error
,现在您的错误消息将等同于 RESOURCE.errors.full_messages
Simply under config/initializers/simple_form.rb
change b.user :error
to b.user :full_error
and now your error messages will be the equivalent of RESOURCE.errors.full_messages
注意:如果您使用带有简单形式的引导程序,您需要更改 simple_form_bootstrap.rb
Note: if you are using bootstrap w/ simple form you change simple_form_bootstrap.rb
这篇关于以简单的形式显示完整的错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!