gluttonberg/spec/controllers/content/pages_spec.rb
# This is cumbersome looking, but it's the only way I could think of
# generating the associated records. In the future I might investigate a 
# neater way of doing it.
This is cumbersome looking, but it's the only way I could think of
generating the associated records. In the future I might investigate a
neater way of doing it.
This is cumbersome looking but it ' s the only way I could think of generating the associated records . In the future I might investigate a neater way of doing it .
def generate_page_articles(pages)
      pages.each do |page|
        page.type.sections.each do |section|
          association = section.send(section.type)
          association.create(:section => section, :page => page)
        end
        Locale.all.each do |locale|
          locale.dialects.all.each do |dialect|
            localization = PageLocalization.generate(:locale => locale, :dialect => dialect)
            page.localizations << localization
            page.articles.each do |article|
              article.localizations << ArticleLocalization.generate
            end
          end
        end
        page.save
      end
    end
def generate_page_articles ( pages ) pages . each do | page | page . type . sections . each do | section | association = section . send ( section . type ) association . create ( :section => section , :page => page ) end Locale . all . each do | locale | locale . dialects . all . each do | dialect | localization = PageLocalization . generate ( :locale => locale , :dialect => dialect ) page . localizations << localization page . articles . each do | article | article . localizations << ArticleLocalization . generate end end end page . save end end
This is cumbersome looking, but it's the only way I could think of
generating the associated records.
This is cumbersome looking but it ' s the only way I could think of generating the associated records .
# Based on the template, generate the content # Generate the localizations # For each article in the page, create a corresponding one for the localization
pages