【发布时间】:2016-06-15 06:30:06
【问题描述】:
我正在尝试创建一个集合选择,它显示来自两个不同模型的两个属性。
我想选择一个帐户。该帐户具有名称和所有者。所有者是一个模型,它也具有属性名称。
使用集合选择时,我希望它显示:account.name + owner.name。这是目前我拥有的 collection_select,它只显示 account.name
<div class="field">
<%= f.label :to_account_id %>
<%= f.collection_select :to_account_id, Account.all, :id, :name %>
</div>
例如:帐户名称为 Main account,并且该帐户的所有者是 Stan,选择时应显示 Stan - Main account .
曾与:
<%= f.collection_select :to_account_id, Account.all.map{|a| ["#{a.owner.name} - #{a.name}", a.id] },:second,:first %>
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-5 collection-select