Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Issue with polymorphic associations
class Task < ActiveRecord::Base
has_one :notification_preference, as: :notifee
accepts_nested_attributes_for :notification_preference
end
class NotificationPreference < ActiveRecord::Base
belongs_to :notifee, polymorphic: true
end
# accepts_nested_attributes_for allows you to do this:
Task.find_or_initialize_by(
notification_preference_attributes: {
# attributes for the NP
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.