I have such task: when user edits his object - first option in the list will be the value of object.
I'm generating my select list using this code:
<%= f.select :category, options_for_select([
"#{@website.category}",
"Banking",
"Computers",
"Coupons",
"Directory",
"Fashion",
"Finance",
"Gifts",
"Maps",
"Media",
"Mobile",
"News",
"Tickets",
"Tech blog",
"Tech website",
"Trains",
"Travel",
"Transportation - general",
"Recipes",
"Another... "])%>
Can anyone suggest how to do it ?
See here the doc about options_for_select
You can set a default value (or selected value) of the select-box as the second argument. In your case it would be like :
<%= f.select :category, options_for_select([
"Banking",
"Computers",
"Coupons",
"Directory",
"Fashion",
"Finance",
"Gifts",
"Maps",
"Media",
"Mobile",
"News",
"Tickets",
"Tech blog",
"Tech website",
"Trains",
"Travel",
"Transportation - general",
"Recipes",
"Another... "], @website.category)%>
Hope this helps!