Topic: Polymorphic associations don't get saved
I try to implement a polymorphic association. Everything seems to work, besides that the associated object dont't get saved.
Here's my simple code:
Simple Person Class
class Person < ActiveRecord::Base
has_many :address_links, :as => :addressable, :dependent => :destroy
has_many :addresses, :through => :address_links
class AddressLink < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
the polymorphic class
class Address < ActiveRecord::Base
I submit a new person and an address to the 'create' action in my person_controller:
@person = Person.new(params[:person])
@address = Address.new(params[:address])
@person.addresses << @address
@ok = @person.save ? true : false
Everything seems alright. I checked the view, I checked the database. @address contains the attributes I submitted via my form, even @person.addresses contains the correct address. @person.save returns true. The adresse just never appears in the database.
Where's my mistake?