From 06ec666fa8fad0aafe7d8e505f6e92b729fccbce Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 22 Mar 2009 17:14:08 +0100 Subject: Finally! The cloning of pages for creating new drafts is now a lot cleaner. I had to search for a while to figure out a better way. Thank you svenfuchs and joshmh for the support! --- app/models/page.rb | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'app/models/page.rb') diff --git a/app/models/page.rb b/app/models/page.rb index 4c4536e..58f9682 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -87,27 +87,23 @@ class Page < ActiveRecord::Base def clone_attributes_from page return nil unless page - + + self.reload + # Clone untranslated attributes - self.tag_list = page.tag_list.join(", ") self.template_name = page.template_name self.published_at = page.published_at - # Clone translated attributes + # Getting rid of the auto-generated empty translations + self.globalize_translations.delete_all - locale_before = I18n.locale - - I18n.available_locales.each do |l| - next if l == :root - I18n.locale = l - page.reload - self.title = page.title unless page.title.try(:fallback?) - self.abstract = page.abstract unless page.abstract.try(:fallback?) - self.body = page.body unless page.body.try(:fallback?) + # Clone translated attributes + page.globalize_translations.each do |translation| + self.globalize_translations.create!(translation.attributes) end - - I18n.locale = locale_before + + self.save end def public? -- cgit v1.3