使用 simple_form 显示基本错误

Show base errors using simple_form

我在模型上有错误而不是模型字段,所以这些被添加到错误[:base]。在我使用的简单表单代码中;

  <%= f.error_notification %>

这显示的是普通错误,而不是基本错误。如何查看基础错误?

只需添加

  <%= f.error :base %>

这将在表格顶部显示基本错误。

如果您希望使用任何基本错误消息覆盖它,

error_notification 接受 message 选项。

<%= f.error_notification message: f.object.errors[:base].to_sentence %>