Class: Gluttonberg::PageObserver
- Inherits:
-
ActiveRecord::Observer
- Object
- ActiveRecord::Observer
- Gluttonberg::PageObserver
- Defined in:
- app/observers/gluttonberg/page_observer.rb
Overview
Observe Page, if there is any change occurred then update its related localizations and contents
Instance Method Summary collapse
-
#after_create(page) ⇒ Object
Generate a series of content model objects 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
This has the page localizations regenerate their path if the slug or parent for this page has changed.
-
#before_update(page) ⇒ Object
This checks to make sure if we need to regenerate paths for child-pages and adds a flag if it does.
Instance Method Details
#after_create(page) ⇒ Object
Generate a series of content model objects for this page based on the specified template. These models will be empty, but ready to be displayed in the admin interface for editing.
11 12 13 14 15 |
# File 'app/observers/gluttonberg/page_observer.rb', line 11 def after_create(page) page.current_user_id = page.user_id create_page_localizations(page) create_page_contents(page) end |
#after_destroy(page) ⇒ Object
If parent page is removed then make sure its children either orphaned or child of their grandfather
34 35 36 |
# File 'app/observers/gluttonberg/page_observer.rb', line 34 def after_destroy(page) Page.delete_all(:parent_id => page.id) end |
#after_update(page) ⇒ Object
This has the page localizations regenerate their path if the slug or parent for this page has changed.
27 28 29 30 31 |
# File 'app/observers/gluttonberg/page_observer.rb', line 27 def after_update(page) if page.paths_need_recaching? page.localizations.each { |l| l.regenerate_path! } end end |
#before_update(page) ⇒ Object
This checks to make sure if we need to regenerate paths for child-pages and adds a flag if it does.
19 20 21 22 23 |
# File 'app/observers/gluttonberg/page_observer.rb', line 19 def before_update(page) if page.parent_id_changed? || page.slug_changed? page.paths_need_recaching = true end end |