Class: Gluttonberg::LocaleObserver

Inherits:
ActiveRecord::Observer
  • Object
show all
Defined in:
app/observers/gluttonberg/locale_observer.rb

Instance Method Summary collapse

Instance Method Details

#after_create(locale) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/observers/gluttonberg/locale_observer.rb', line 5

def after_create(locale)   
  pages = Page.all
  
  pages.each do |page|
    #create localizations for all pages for new locale
    new_localizations = []
    new_localizations << page.localizations.create(
      :name     => page.name,
      :locale_id   => locale.id
    )
    
    # create content localizations
    unless page.description.sections.empty?
      Rails.logger.info("Generating stubbed content for all pages using new localizations")
      page.description.sections.each do |name, section|
        # Create the content
          association = page.send(section[:type].to_s.pluralize)
          content = association.find(:first , :conditions => {:section_name => name})
          # Create each localization
           if content && content.class.localized?
               new_localizations.each do |localization|
                 content.localizations.create(:parent => content, :page_localization => localization)
               end
          end
      end
    end
    
  end
  
end

#after_update(locale) ⇒ Object



38
39
40
41
42
# File 'app/observers/gluttonberg/locale_observer.rb', line 38

def after_update(locale)
  existing_localization_ids = []
  remove_list = []
  new_localizations = []
end