我正在尝试创建一个表单,允许一个组选择他们可以在系统中使用的多个模块。不幸的是,每次我尝试这个时,我都会遇到一些疯狂的关联错误,我不知道为什么。
这是我的表格的代码
<%= form_for @group, :url => admin_groups_path, :html => { :class => 'entry' } do |f| %>
<%= render :partial => 'shared/error_messages', :locals => { :object => @group } %>
<div class="g12">
<fieldset>
<fieldset>
<legend>Add Group</legend>
<div class="simple_format">
<section class="g3">
<%= f.label :name %>
<div><%= f.text_field :name, :size => 15 %></div>
</section>
<section class="g3">
<%= f.label :is_facility, 'Facility?' %>
<div style="display:block;margin: 0 auto;width:25px;"><%= f.check_box :is_facility %></div>
</section>
<section class="g3">
<%= f.label :parent_id %>
<div style="display:block;margin: 0 auto;width:25px;"><%= f.collection_select :parent_id, current_group.self_and_descendants.reject(&:is_facility), :id, :name %></div>
</section>
<section class="g3">
<%= f.label :time_zone, 'Time Zone' %>
<div><%= f.select :time_zone, ActiveSupport::TimeZone.all.map(&:name).select {|x| x=~ /US/} %></div>
</section>
</div>
<div class="simple_format">
<section class="g3">
<%= f.label :federal_tax_number, 'Federal Tax ID' %>
<div><%= f.text_field :federal_tax_number, :size => 15 %></div>
</section>
<section class="g3">
<%= f.label :national_provider_identifier, 'National Provider ID' %>
<div><%= f.text_field :national_provider_identifier, :size => 15 %></div>
</section>
<section class="g3">
<%= f.label :modules, 'Allowed Modules' %>
<div><%= f.collection_select :group_access_modules, AccessModule.all, :id, :name, {}, {:multiple => true} %></div>
</section>
</div>
<section class="g12">
<div><%= f.submit "Add Group", { :class => 'form-submit' } %></div>
</section>
</fieldset>
</fieldset>
</div>
<% end %>
这是我的模型
class Group < ActiveRecord::Base
has_many :group_access_modules
end
这是我在保存时遇到的错误
<h1>
ActiveRecord::AssociationTypeMismatch
in Admin::GroupsController#create
</h1>
<pre>GroupAccessModule(#70245162706560) expected, got String(#70245155065480)</pre>
我现在完全迷路了。