【发布时间】:2011-04-21 18:55:18
【问题描述】:
我有两个模型 - 联系人和组织 - 设置为 has_and_belongs_to_many 关系:
class Contact < ActiveRecord::Base
has_and_belongs_to_many :organizations
end
class Organization < ActiveRecord::Base
has_and_belongs_to_many :contacts
end
在联系人的新视图中,我有以下collection_select:
<%= collection_select('contact', 'organization_ids', @organizations, :id, :name, {}, { :multiple => :true, :name => 'contact[organization_ids][]'}) %>
这可行,但为这种关系创建多选框似乎过于复杂。
对于这种特殊的关系是否有更好的帮手?我更喜欢使用多选框 - 而不是复选框。
【问题讨论】:
标签: ruby-on-rails view has-and-belongs-to-many