开发者

Rail3 attr_accessbile for nested models

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜