Search code examples
ruby-on-railssimple-form

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


Solution

  • 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