如何使用simple_form显示用户列表?

时间:2011-01-26 22:44:21

标签: ruby-on-rails forms

当我这样做时:<%= f.association :user, :collection => User.where(:country_id => 1) %>

我的下拉列表中填充了以下行: #<User:0x0000010b98d170>

相反,我想显示一封与用户ID相关联的电子邮件。

我还没有找到在使用关联时如何覆盖simple_form的值/内容默认值。

有人可以帮忙吗?

谢谢你, P上。

1 个答案:

答案 0 :(得分:18)

虽然github上的页面(https://github.com/plataformatec/simple_form)没有说,但我想它与示例f.input :age, :collection => 18..60

相同

您可以使用:label_method:value_method

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

我以前没用过它。请告诉我它是否无效。