CaptainCarl
CaptainCarl

Reputation: 3489

On edit, use selected in select form helper

I've got a select in my form with all the groups. So I loop through all available groups.

However; When I try to edit a client, the selectbox doesn't add a selected to the group i've selected. Most likely because of the loop in it. How can I make the right one selected?

<%= f.select(:group_id, options_for_select(@usersGroups.collect{ |u| [u.name, u.id] }), :prompt => "Kies een groep") %>

Upvotes: 0

Views: 121

Answers (1)

Adeptus
Adeptus

Reputation: 683

options_for_select documentation

So in your situation probably something like:

<%= f.select(:group_id, options_for_select(@usersGroups.collect{ |u| [u.name, u.id] }, @client.group_id), :prompt => "Kies een groep") %>

Upvotes: 1

Related Questions