我有一个select_tag并将一个选项值设为默认值,我想根据条件将某个选项设为禁用
<% disabled_option = ["options for disabled"]%>
<%= select_tag "product_dropdown", options_for_select(ProductType.get_all_products, @type), {:disabled => disabled_options} %>
上面的代码抛出错误错误的参数数量(3为2) 甚至我用过
<%= select_tag "product_dropdown", options_for_select(ProductType.get_all_products, @type, {:disabled => disabled_options}) %>
这也不起作用我该怎么做
答案 0 :(得分:0)
这是options_for_select
options_for_select(["value1", "value2", "value3", "value4"], disabled: ["value1", "value4"])
你传递了三个arguments
options_for_select(ProductType.get_all_products, @type, {:disabled => disabled_options})
所以它应该如下所示,ProductType.get_all_products
应该是array
修改强>
options_for_select(ProductType.get_all_products, selected: @type, disabled: disabled_options)