I am struggling to see why the attributes are still protected. Is there a scope within the parent model that I should be using to allow those attributes?
# 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,})\Z/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
精彩评论