diff --git a/app/models/organization.rb b/app/models/organization.rb index b3c36f7..47a4224 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -53,7 +53,7 @@ class Organization < Profile true end - after_create :create_default_set_of_blocks_for_organization + hacked_after_create :create_default_set_of_blocks_for_organization def create_default_set_of_blocks_for_organization # "main" area # nothing ..., MainBlock is already there diff --git a/app/models/person.rb b/app/models/person.rb index 7871291..ae51d4d 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -59,7 +59,7 @@ class Person < Profile # FIXME this is *weird*, because this class is not inheriting the callback # from Profile !!! - after_create :create_default_set_of_boxes_for_person + hacked_after_create :create_default_set_of_boxes_for_person def create_default_set_of_boxes_for_person 3.times do self.boxes << Box.new @@ -82,6 +82,6 @@ class Person < Profile # FIXME this is *weird*, because this class is not inheriting the callbacks before_create :set_default_environment - after_create :insert_default_homepage_and_feed + hacked_after_create :insert_default_homepage_and_feed end diff --git a/app/models/profile.rb b/app/models/profile.rb index dda843e..8b90477 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -96,7 +96,7 @@ class Profile < ActiveRecord::Base end # registar callback for creating boxes after the object is created. - after_create :create_default_set_of_boxes + hacked_after_create :create_default_set_of_boxes # creates the initial set of boxes when the profile is created. Can be # overriden for each subclass to create a custom set of boxes for its @@ -236,7 +236,7 @@ class Profile < ActiveRecord::Base false end - after_create :insert_default_homepage_and_feed + hacked_after_create :insert_default_homepage_and_feed def insert_default_homepage_and_feed hp = self.articles.build(:name => _('Home page'), :body => _("
This is a default homepage created for %s. It can be changed though the control panel.
") % [ self.name, self.name]) hp.save! diff --git a/config/environment.rb b/config/environment.rb index 78b37a3..68dbe5e 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -84,6 +84,7 @@ require 'acts_as_filesystem' require 'acts_as_searchable' require 'acts_as_having_boxes' require 'acts_as_having_settings' +require 'hacked_after_create' # to the hell, I want all my models loaded before the application run anything Dir.glob("#{RAILS_ROOT}/app/models/*.rb").each do |model| diff --git a/lib/hacked_after_create.rb b/lib/hacked_after_create.rb new file mode 100644 index 0000000..60848f2 --- /dev/null +++ b/lib/hacked_after_create.rb @@ -0,0 +1,11 @@ +class << ActiveRecord::Base + # it seems that in some enviroments after_create hook is not inherited. This + # method calls after_create only if the callback is not already there. + def hacked_after_create(sym) + current = after_create + if !current.include?(sym) + current = after_create(sym) + end + current + end +end -- libgit2 0.21.2