Class: Gluttonberg::PageObserver
- Inherits:
-
ActiveRecord::Observer
- Object
- ActiveRecord::Observer
- Gluttonberg::PageObserver
- Defined in:
- app/observers/gluttonberg/page_observer.rb
Instance Method Summary collapse
-
#after_create(page) ⇒ Object
Generate a series of content models for this page based on the specified template.
-
#after_destroy(page) ⇒ Object
If parent page is removed then make sure its children either orphaned or child of their grandfather.
- #after_update(page) ⇒ Object
- #before_update(page) ⇒ Object
Instance Method Details
#after_create(page) ⇒ Object
Generate a series of content models for this page based on the specified template. These models will be empty, but ready to be displayed in the admin interface for editing.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/observers/gluttonberg/page_observer.rb', line 9 def after_create(page) puts("Generating page localizations") Locale.all.each do |locale| loc = page.localizations.create( :name => page.name, :locale_id => locale.id ) end unless page.description.sections.empty? puts("Generating stubbed content for new page") page.description.sections.each do |name, section| # Create the content association = page.send(section[:type].to_s.pluralize) content = association.create(:section_name => name) # Create each localization if content.class.localized? page.localizations.all.each do |localization| content.localizations.create(:parent => content, :page_localization => localization) end end end end end |
#after_destroy(page) ⇒ Object
If parent page is removed then make sure its children either orphaned or child of their grandfather
52 53 54 |
# File 'app/observers/gluttonberg/page_observer.rb', line 52 def after_destroy(page) Page.delete_all(:parent_id => page.id) end |
#after_update(page) ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/observers/gluttonberg/page_observer.rb', line 43 def after_update(page) # This has the page localizations regenerate their path if the slug or # parent for this page has changed. if page.paths_need_recaching? page.localizations.each { |l| l.regenerate_path! } end end |
#before_update(page) ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/observers/gluttonberg/page_observer.rb', line 35 def before_update(page) # This checks to make see if we need to regenerate paths for child-pages # and adds a flag if it does. if page.parent_id_changed? || page.slug_changed? page.paths_need_recaching = true end end |