svenyonson
svenyonson

Reputation: 1939

Using collection_select with an array

I am trying to use a dropdown in my edit.html.erb that is populated with a list of icon filenames (on the server). I used an array of label/value pairs to populate the list, which works great, except I want the dropdown to be preselected with the value that is currently in the record. When using collection_select with an actual model, the current value is selected. Do I have to create a tableless model instead of the array of structs to make this work?

Upvotes: 0

Views: 3059

Answers (1)

Kylo
Kylo

Reputation: 2320

you can use options_for_select (API) and pass value that you want to be selected as second argument

Upvotes: 1

Related Questions