Basic Group Model:
class Group < ActiveRecord::Base
@@ItemType = 'GroupItem' # Base ItemType
after_initialize :default_item_type
has_many :group_assignments
has_many :items, through: :group_assignments, source: :groupable, source_type: @@ItemType, dependent: :destroy
accepts_nested_attributes_for :items, allow_destroy: true
private
def default_item_type
self.item_type = @@ItemType if self.new_record?
end
end
Namespaced Model:
class Gradation::Group < Group
@@ItemType = 'Gradation' # Base ItemType
after_initialize :default_item_type
has_many :group_assignments
has_many :items, through: :group_assignments, source: :groupable, source_type: @@ItemType, dependent: :destroy
accepts_nested_attributes_for :items, allow_destroy: true
private
def default_item_type
self.item_type = @@ItemType if self.new_record?
end
end
I am attempting to have a field *item_type* be set on the *after_initialize* callback, but not matter what I do, the callback is only triggered on the regular group model and not the namespaced one.
I am struggling to understand why this is the expected behavior, and also how to get callbacks to work for the namespaced Group.