After upgrading from Rails 3.2 to 4.1, the following code which used to work is now failing:
in a controller/spec:
post = user.posts.build
post.contacts << contact # contact is a persisted record
post.save! # now fails
I'm basically trying to save the post along with its associated contact, which is supposed to create a contact_publishment
record on-the-fly.
The error is on the new contact_publishment
record: "Publishable can't be blank"
the model:
class Contact
...
has_many :contact_publishments
...
end
class ContactPublishment
...
belongs_to :publishable, polymorphic: true
belongs_to :contact
validates_uniqueness_of :publishable_id, :scope => [:contact_id, :publishable_type]
validates_presence_of :contact, :publishable
...
end
class Post
...
has_many :contact_publishments, as: :publishable
has_many :contacts, through: :contact_publishments
...
end