当我这样做时:<%= f.association :user, :collection => User.where(:country_id => 1) %>
我的下拉列表中填充了这样的行:#<User:0x0000010b98d170>
相反,我想显示一封与用户 ID 相关的电子邮件。
我还没有找到在使用关联时如何覆盖 simple_form 的值/内容默认值。
任何人都可以帮忙吗?
谢谢你,
P。
请您参考如下方法:
虽然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
我之前没有使用它。如果它不起作用,请告诉我。




