Toontje
Toontje

Reputation: 1485

simple_form show selected option

I want to show a select box with users, using simple_form.

currently my code looks like this:

<%= f.input :user, collection: get_members, label_method: :fullname %>

this is working, but the problem is that the select box doesn't show the selected option.

Does anybody know how to show a selected option with simple_form?

thanks for your help,

Anthony

Upvotes: 0

Views: 1646

Answers (1)

bo-oz
bo-oz

Reputation: 2872

You can set selected to the value of the user_id, but simple_form should be smart enough to figure this out by itself, so probably something wrong somewhere else (controller?):

   <%= f.input :user, collection: get_members, label_method: :fullname, selected: member.id %>

Sorry, you probably need f.association:

f.association :user, collection: get_members

Upvotes: 1

Related Questions