Reputation: 6612
I have a form for both the new and edit action. one of the fields is a selectbox and when editing the select should show the value from the database. This is what I have now, but it shows "basic" as value, not "premium" (which is stored as database value):
<%= s_form.select(:name,
options_for_select([['Basic', 'basic'], ['Premium', 'premium']]),
:selected => params[:name]) %>
Any suggestions how to make this work?
Upvotes: 3
Views: 2587
Reputation: 20724
You should pass the selected option to the option_for_select helper like:
<%= s_form.select(:name, options_for_select([['Basic', 'basic'], ['Premium', 'premium']], :selected => params[:name])) %>
Upvotes: 8