How to display a list of users using simple_form?

When I do this: <%= f.association :user, :collection => User.where(:country_id => 1) %>

My dropdown list displays strings such as: #<User:0x0000010b98d170>

Instead, I want to display the email associated with the user ID.

I still need to find how to override the default / content defaults for simple_form when using associations.

Can anyone help?

Thank you R.

+5
source share
1 answer

Although the page on github (https://github.com/plataformatec/simple_form) did not say, but I assume that it is the same as in the example f.input :age, :collection => 18..60

You can use :label_methodand :value_method:

f.association :user, :collection => User.where(:country_id => 1), :label_method => :name, :value_method => :id

I have not used it before. Please tell me if this does not work.

+18

All Articles