我遇到批量分配错误。而且我不明白为什么它会给我错误这里是错误
ActiveModel::MassAssignmentSecurity::Error in CustomersController#edit
Can't mass-assign protected attributes: gender
这是我的模型
Customer GenderManager Gender
ID Id Id
First isVisible Description
Last GroupID
Email
...
这里是我的关系
class Customer < ActiveRecord::Base
# RELATIONSHIP
#Gender
has_many :gender_managers
accepts_nested_attributes_for :gender_managers, allow_destroy: :true
end
class GenderManager < ActiveRecord::Base
# RELATIONSHIP
belongs_to :customer
has_one :gender
attr_accessible :customer_id, :friendship_group_id, :isUsed,
:isVisible, :genders_attributes
accepts_nested_attributes_for :gender, allow_destroy: :true
end
class Gender < ActiveRecord::Base
belongs_to :gender_manager
attr_accessible :description, :gender_managers_id
end
客户控制器
def edit
@customer = Customer.find(params[:id])
@customer.gender_managers.build(:gender => Gender.new)
@bm = current_customer.book_managers.build
end
形式
<%= form_for @customer, :html => {:multipart => true} do |f| %>
<div class="customer_edit_error_message">
<%= render 'shared/error_messages' %>
</div>
<fieldset>
<div class="customer_edit_name">
<%= f.label :first_name %>
<%= f.text_field :first_name %>
</div>
<div class="customer_edit_middle_name">
<%= f.label :middle_name %>
<%= f.text_field :middle_name %>
</div>
<div class="customer_edit_last_name">
<%= f.label :last_name %>
<%= f.text_field :last_name %>
</div>
<%= f.fields_for :gender_managers do |gendermanagers| %>
<fieldset>
<%= gendermanagers.fields_for :genders do |genders| %>
<%= genders.label :description %>
<%= genders.select :description %>
<% end %>
<div><%= gendermanagers.label :friendship_group_id, "Show To: " %>
<%= gendermanagers.text_field :friendship_group_id %></div>
<div><%= gendermanagers.check_box :isVisible %>
<%= gendermanagers.label :isVisible %></div>
</fieldset>
<% end %>
<div class="customer_edit_button">
<%= f.submit "Save changes", class: "button_accept" %>
</div>
<% end %>