include_blank 形式 select_option 无效

include_blank in form select_option not working

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

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

没有给出预期的结果。

User::ROLE是用户class中的一个数组,如下:

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

如何将字段中的 select 选项设置为 return 第一个 select 的空白选项,而不必将空白选项作为 [=] 的第一个元素15=]数组?谢谢

下面应该修复它:

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

方法签名如下:

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

API开始,应该是

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