简体   繁体   English

如何显示错误消息以在集合选择工作simple_form上进行验证?

[英]How do I display error messages for validation on a collection select work simple_form?

I'm on mobile so don't have access to my code until later. 我在移动设备上,因此直到以后才能访问我的代码。 But the basics are this: I have a simple_form to create/edit a listing on my site. 但是基础是这样的:我有一个simple_form在我的网站上创建/编辑列表。 Certain parameters are required. 某些参数是必需的。 I use validates presence of in the model. 我使用验证模型中的存在。 When submitting the form, if I text box that is required isn't filled out, the validation works fine, error pops up and says please fill in. When a button is not selected for one of the collection selects, nothing happens. 提交表单时,如果未填写所需的“我”文本框,则验证工作正常,错误弹出并提示“请填写”。如果未为所选集合之一选择按钮,则不会发生任何事情。 Obviously the validation is working because the form won't submit, but no error is thrown. 显然,验证是有效的,因为表单不会提交,但不会引发任何错误。 Any ideas on how to get the error to show for a collection select with radio buttons? 关于如何使错误显示给收藏集的任何想法都可以通过单选按钮选择?

In your form do you have? 您有表格吗?

<%= form.error_notification %>

Or you can do it in a different way, if you don't want to do it with the form helper. 或者,如果您不想使用表单帮助器,也可以采用其他方式。

<%= @instance_variable.errors.full_messages if @instance_variable.errors.any? %>

You can read more here. 您可以在这里阅读更多内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM