表单select_option中的include_blank不起作用

时间:2015-06-14 10:43:24

标签: ruby-on-rails form-for

我正在尝试在选择字段中包含默认的空白第一个选项,如下所示:

= f.select :role, options_for_select(User::ROLE), {}, include_blank: true, class: "form-control"

没有给出预期的结果。

User::ROLE是User类中的数组,如下所示:

ROLE = ["user", "doctor", "manager"]

如何在字段中选择选项以返回第一个选择的空白选项,而不必将空白选项包含在ROLE数组的第一个元素中?感谢

2 个答案:

答案 0 :(得分:3)

下面应该修复它:

= f.select :role, options_for_select(User::ROLE), { include_blank: true} , { class: "form-control" }

以下是方法签名:

select(object, method, choices = nil, options = {}, html_options = {}, &block) public

答案 1 :(得分:0)

来自API,它应该是

= f.select :role, options_for_select(User::ROLE),{include_blank: true}, {class: "form-control" }