开发者

How to display a list of users with simple_form?

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

My dropdown is populated with lines like this: #<User:0x0000010b98d170>

Instead, I would like to display an email, that is tied to the id o开发者_开发百科f the users.

I have yet to find how to override the value / content defaults of simple_form when using associations.

Can anyone help?

thank you, P.


Although the page on github (https://github.com/plataformatec/simple_form) didn't say, but I guess it's the same as the example f.input :age, :collection => 18..60

You could use :label_method and :value_method:

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

I did not use it before. Please tell me if it does not work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜