Rails选择标记中的参数数量错误(1 ... 4为5)

时间:2016-05-17 21:28:53

标签: ruby-on-rails ruby

在Rails中传递select中的参数时遇到问题:

  

错误的参数数量(5为1..4)

以下是代码:

<dd><%= f.select :codes, options_for_select(CarParts::CODES), {include_blank: "Select Code"}, {required: true}, {}, {onchange: "myFunc(this);"} %></dd>

删除空哈希会返回相同的错误。虽然删除include_blankrequired属性同时保留它似乎可以正常工作。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

使用此:

<dd><%= f.select :codes, options_for_select(CarParts::CODES), { include_blank: "Select Code" }, { required: true, onchange: "myFunc(this);"} %></dd>

include_blank进入optionsrequiredonchange是HTML选项。以下是Form Helper select的API文档以供参考和示例。