以下是我的代码,
<%= f.collection_select :event_member_id, EventMember.all, :id, :company_member_id, :prompt => "Please select" %>
此处:company_member_id
是EventMember
类中的foreign_key,我想将text_method显示为company_member_email而不是company_member_id,
所以我的collection_select应该如下所示,
<%= f.collection_select :event_member_id, EventMember.all, :id, :'company_member.email', :prompt => "Please select" %>
如何实现上述...... !!!
答案 0 :(得分:1)
在EventMember
模态中: -
def company_member_email
return self.company_member.email unless self.company_member.nil?
""
end
收藏品如下: -
<%= f.collection_select :event_member_id, EventMember.all, :id, :company_member_email, :prompt => "Please select" %>