Orsay
Orsay

Reputation: 1130

Select tag : How to use params to set the selected value?

I have a select tag with 2 options :

 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 ?"

When one of this options are selected, the form is automatically submit. I would like to keep the params in first position. I mean visible without clicking on the select, at the place of "which products".

Upvotes: 6

Views: 5578

Answers (1)

Orsay
Orsay

Reputation: 1130

I finally change the syntax and it works fine using :options_for_select(:collection, :selected)

So there is my code now :

= select_tag :product,  options_for_select(["Product1", "Product2"], params[:product]), id: "different_option_value_html", onchange: "this.form.submit();", include_blank: "Which product ?"

Upvotes: 6

Related Questions