我很难理解为什么这些属性仍然受到保护。父模型中是否有一个范围,我应该使用它来允许这些属性?
# Email model
class EmailAddress < ActiveRecord::Base
belongs_to :emailable, :polymorhpic => true
validates_presence_of :address
validates_format_of :address, :with => /A([^@s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})/i
attr_accessible :address, :location
end
# Company model
class Company < ActiveRecord::Base
has_many :email_addresses, :as => :emailable, :dependent => :destroy
validates_presence_of :company_name
accepts_nested_attributes_for :email_addresses, :reject_if => proc { |attributes| attributes[:address].blank? }
attr_accessible :company_name, :background, :email_addresses_attributes
end
# Error log
WARNING: Can t mass-assign protected attributes: address, location