Class: Gluttonberg::PageLocalizationObserver
- Inherits:
-
ActiveRecord::Observer
- Object
- ActiveRecord::Observer
- Gluttonberg::PageLocalizationObserver
- Defined in:
- app/observers/gluttonberg/page_localization_observer.rb
Overview
Observe PageLocalization for any path/slug related changes
Instance Method Summary collapse
-
#after_save(page_localization) ⇒ Object
This is the business end.
-
#before_validation(page_localization) ⇒ Object
Every time the localization is updated, we need to check to see if the slug has been updated.
Instance Method Details
#after_save(page_localization) ⇒ Object
This is the business end. If the paths do have to be recached, we pile through all the decendent localizations and tell each of those to recache. Each of those will then also be observed and have their children updated as well.
22 23 24 25 26 27 28 29 30 |
# File 'app/observers/gluttonberg/page_localization_observer.rb', line 22 def after_save(page_localization) if page_localization.paths_need_recaching? and !page_localization.page.children.blank? decendant_pages = page_localization.page.children decendant_pages.each do |d_p| update_decendants(page_localization, d_p) end end end |
#before_validation(page_localization) ⇒ Object
Every time the localization is updated, we need to check to see if the slug has been updated. If it has, we need to update it’s cached path and also the paths for all it’s decendants.
9 10 11 12 13 14 15 16 |
# File 'app/observers/gluttonberg/page_localization_observer.rb', line 9 def before_validation(page_localization) if page_localization.slug_changed? || page_localization.new_record? page_localization.paths_need_recaching = true page_localization.regenerate_path elsif page_localization.path_changed? page_localization.paths_need_recaching = true end end |