Rails选择所需格式的帮助程序True无效 [英] Rails Select helper in form required True not working
问题描述
我有一个Rails 3.2.21应用程序,其中我正在使用 select
助手,其格式如下:
I have a Rails 3.2.21 app in which I'm using a select
helper in a form like so:
<%= f.select :phys_option, options_for_select([["N/A", "n/a"], ["No", "no"], ["Yes", "yes"]], :selected => @call.phys_option), :include_blank => true, :required => true, :class => 'select' %>
这与选择选项(包括空白选项等)的基本功能一起使用.但是不起作用的是:required =>.true
或:class =>'选择'
.即使选择为空白,并且select2 gem select
的类在此辅助方法上不起作用,我也可以提交表单.
This works with basic functionality for selecting an option, including a blank option, etc. But what doesn't work is the :required => true
or the :class => 'select'
. I can submit the form even when the selection is blank and my class for the select2 gem select
doesn't work on this helper method.
我的语法错误还是我遗漏了一些东西?我可以调用模型验证来确保填写字段,但是我宁愿避免进行更多的模型验证,并尝试使用:required =>true
强制选择.
Is my syntax wrong or am I missing something? I can call a model validation to ensure the fields are filled out, but I'd much rather avoid more model validations and try to use the :required => true
to force a selection.
有什么想法为什么不起作用?
Any thoughts on why this isn't working?
如果您需要更多详细信息和/或代码,请告诉我.
If you need further detail and/or code, please let me know.
推荐答案
尝试一下:
<%= f.select :phys_option, options_for_select(
[["N/A", "n/a"], ["No", "no"], ["Yes", "yes"]],
:selected => @call.phys_option),
{:include_blank => true},
{:required => true, :class => 'select'} %>
这篇关于Rails选择所需格式的帮助程序True无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!