diff options
Diffstat (limited to 'app/models/page.rb')
| -rw-r--r-- | app/models/page.rb | 24 |
1 files changed, 10 insertions, 14 deletions
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 | |||
| 87 | 87 | ||
| 88 | def clone_attributes_from page | 88 | def clone_attributes_from page |
| 89 | return nil unless page | 89 | return nil unless page |
| 90 | 90 | ||
| 91 | self.reload | ||
| 92 | |||
| 91 | # Clone untranslated attributes | 93 | # Clone untranslated attributes |
| 92 | |||
| 93 | self.tag_list = page.tag_list.join(", ") | 94 | self.tag_list = page.tag_list.join(", ") |
| 94 | self.template_name = page.template_name | 95 | self.template_name = page.template_name |
| 95 | self.published_at = page.published_at | 96 | self.published_at = page.published_at |
| 96 | 97 | ||
| 97 | # Clone translated attributes | 98 | # Getting rid of the auto-generated empty translations |
| 99 | self.globalize_translations.delete_all | ||
| 98 | 100 | ||
| 99 | locale_before = I18n.locale | 101 | # Clone translated attributes |
| 100 | 102 | page.globalize_translations.each do |translation| | |
| 101 | I18n.available_locales.each do |l| | 103 | self.globalize_translations.create!(translation.attributes) |
| 102 | next if l == :root | ||
| 103 | I18n.locale = l | ||
| 104 | page.reload | ||
| 105 | self.title = page.title unless page.title.try(:fallback?) | ||
| 106 | self.abstract = page.abstract unless page.abstract.try(:fallback?) | ||
| 107 | self.body = page.body unless page.body.try(:fallback?) | ||
| 108 | end | 104 | end |
| 109 | 105 | ||
| 110 | I18n.locale = locale_before | 106 | self.save |
| 111 | end | 107 | end |
| 112 | 108 | ||
| 113 | def public? | 109 | def public? |
