Select tag : 如何使用params设置选中值?
Select tag : How to use params to set the selected value?
我有一个带有 2 个选项的 select 标签:
select_tag :type, options_for_select("<option value = 'produit1'>Produit1</option><option value = 'Produit2'>Produit2</option>", params[:product]), id: "different_option_value_html", onchange: "this.form.submit();", include_blank: "Which products ?"
当select输入其中一个选项时,表单会自动提交。我想将参数保持在第一位。我的意思是在 "which products".
的位置不点击 select 就可见
我终于更改了语法,使用 :options_for_select(:collection, :selected)
它工作正常
现在有我的代码了:
= select_tag :product, options_for_select(["Product1", "Product2"], params[:product]), id: "different_option_value_html", onchange: "this.form.submit();", include_blank: "Which product ?"
我有一个带有 2 个选项的 select 标签:
select_tag :type, options_for_select("<option value = 'produit1'>Produit1</option><option value = 'Produit2'>Produit2</option>", params[:product]), id: "different_option_value_html", onchange: "this.form.submit();", include_blank: "Which products ?"
当select输入其中一个选项时,表单会自动提交。我想将参数保持在第一位。我的意思是在 "which products".
的位置不点击 select 就可见我终于更改了语法,使用 :options_for_select(:collection, :selected)
现在有我的代码了:
= select_tag :product, options_for_select(["Product1", "Product2"], params[:product]), id: "different_option_value_html", onchange: "this.form.submit();", include_blank: "Which product ?"