Commit 4bd17eba2a498536fae248b0a0ac5362da4a4b3a
1 parent
2ef3626d
Exists in
master
and in
29 other branches
ActionItem154: adding a workaround for the fact that after_create callbacks are …
…not being inherited by subclasses in my development environment but are inherited in the server environment. Very weird. git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1412 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
17 additions
and
5 deletions
Show diff stats
app/models/organization.rb
... | ... | @@ -53,7 +53,7 @@ class Organization < Profile |
53 | 53 | true |
54 | 54 | end |
55 | 55 | |
56 | - after_create :create_default_set_of_blocks_for_organization | |
56 | + hacked_after_create :create_default_set_of_blocks_for_organization | |
57 | 57 | def create_default_set_of_blocks_for_organization |
58 | 58 | # "main" area |
59 | 59 | # nothing ..., MainBlock is already there | ... | ... |
app/models/person.rb
... | ... | @@ -59,7 +59,7 @@ class Person < Profile |
59 | 59 | |
60 | 60 | # FIXME this is *weird*, because this class is not inheriting the callback |
61 | 61 | # from Profile !!! |
62 | - after_create :create_default_set_of_boxes_for_person | |
62 | + hacked_after_create :create_default_set_of_boxes_for_person | |
63 | 63 | def create_default_set_of_boxes_for_person |
64 | 64 | 3.times do |
65 | 65 | self.boxes << Box.new |
... | ... | @@ -82,6 +82,6 @@ class Person < Profile |
82 | 82 | |
83 | 83 | # FIXME this is *weird*, because this class is not inheriting the callbacks |
84 | 84 | before_create :set_default_environment |
85 | - after_create :insert_default_homepage_and_feed | |
85 | + hacked_after_create :insert_default_homepage_and_feed | |
86 | 86 | |
87 | 87 | end | ... | ... |
app/models/profile.rb
... | ... | @@ -96,7 +96,7 @@ class Profile < ActiveRecord::Base |
96 | 96 | end |
97 | 97 | |
98 | 98 | # registar callback for creating boxes after the object is created. |
99 | - after_create :create_default_set_of_boxes | |
99 | + hacked_after_create :create_default_set_of_boxes | |
100 | 100 | |
101 | 101 | # creates the initial set of boxes when the profile is created. Can be |
102 | 102 | # overriden for each subclass to create a custom set of boxes for its |
... | ... | @@ -236,7 +236,7 @@ class Profile < ActiveRecord::Base |
236 | 236 | false |
237 | 237 | end |
238 | 238 | |
239 | - after_create :insert_default_homepage_and_feed | |
239 | + hacked_after_create :insert_default_homepage_and_feed | |
240 | 240 | def insert_default_homepage_and_feed |
241 | 241 | hp = self.articles.build(:name => _('Home page'), :body => _("<h1>%s's home page</h1> <p>This is a default homepage created for %s. It can be changed though the control panel.</p>") % [ self.name, self.name]) |
242 | 242 | hp.save! | ... | ... |
config/environment.rb
... | ... | @@ -84,6 +84,7 @@ require 'acts_as_filesystem' |
84 | 84 | require 'acts_as_searchable' |
85 | 85 | require 'acts_as_having_boxes' |
86 | 86 | require 'acts_as_having_settings' |
87 | +require 'hacked_after_create' | |
87 | 88 | |
88 | 89 | # to the hell, I want all my models loaded before the application run anything |
89 | 90 | Dir.glob("#{RAILS_ROOT}/app/models/*.rb").each do |model| | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +class << ActiveRecord::Base | |
2 | + # it seems that in some enviroments after_create hook is not inherited. This | |
3 | + # method calls after_create only if the callback is not already there. | |
4 | + def hacked_after_create(sym) | |
5 | + current = after_create | |
6 | + if !current.include?(sym) | |
7 | + current = after_create(sym) | |
8 | + end | |
9 | + current | |
10 | + end | |
11 | +end | ... | ... |