Saturday, December 18, 2010

ActiveRecord::AssociationTypeMismatch error while using accepts_nested_attributes_for

ActiveRecord::AssociationTypeMismatch error while using accepts_nested_attributes_for

if you are using  accepts_nested_attributes_for in you model don't use a model named Attribute.


class Event < ActiveRecord::Base
  has_many      :attributes , :dependent => :destroy
  accepts_nested_attributes_for :attributes, :reject_if => lambda { |a| a.values.all?(&:blank?) }, :allow_destroy => true
end



class Attribute < ActiveRecord::Base
  belongs_to :event
end
i have the above code in project when i change the model name to something other than attribute every thing work fine

No comments:

Post a Comment