From b5dc7515f7db7dadda1b40d041e1725e67c935be Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 26 Jul 2012 13:27:27 +0800 Subject: [PATCH] Fix bugs after i18n_variable removal --- app/models/site.rb | 14 ++++++-------- app/views/admin/sites/site_info.html.erb | 13 ++++++------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index faa7ece37..46038eb2b 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -40,17 +40,15 @@ class Site end METAS.each do |meta| - define_method meta do + define_method meta do |locale| fetch_meta = self.site_metas.where(key: meta).limit(1) - fetch_meta.blank? ? nil : fetch_meta[0].i18n_variable + fetch_meta.blank? ? nil : fetch_meta[0].title_translations[locale] end define_method "#{meta}=" do |values| - if a = self.send(meta) - a.update_attributes(values) - else - a = self.site_metas.build(key: meta) - a.build_i18n_variable(values) - end + fetch_meta = self.site_metas.where(key: meta).limit(1)[0] rescue nil + fetch_meta = self.site_metas.build(key: meta) if fetch_meta.blank? + fetch_meta.title_translations = values + fetch_meta.save end end diff --git a/app/views/admin/sites/site_info.html.erb b/app/views/admin/sites/site_info.html.erb index 4ce99df13..cdd7ea541 100644 --- a/app/views/admin/sites/site_info.html.erb +++ b/app/views/admin/sites/site_info.html.erb @@ -38,9 +38,8 @@
- <% #TODO: set keywords into meta %> - <%= f.fields_for :keywords, @site.keywords do |f| %> - <%= f.text_area locale, :class => "input-xxlarge textarea-height-s" %> + <%= f.fields_for :keywords do |f| %> + <%= f.text_area locale, :class => "input-xxlarge textarea-height-s", :value => (@site.keywords(locale) rescue nil) %> <% end %>

<%= (t 'admin.site_keywords_help').html_safe %>

@@ -48,8 +47,8 @@
- <%= f.fields_for :description_translations do |f| %> - <%= f.text_area locale, :class => "input-xxlarge textarea-height-s", :value => (@site.description_translations[locale] %> + <%= f.fields_for :description do |f| %> + <%= f.text_area locale, :class => "input-xxlarge textarea-height-s", :value => (@site.description(locale) rescue nil) %> <% end %>

<%= (t 'admin.site_description_help').html_safe %>

@@ -58,7 +57,7 @@
<%= f.fields_for :footer_translations do |f| %> - <%= f.text_area locale, :class => "tinymce_textarea input-xxlarge", :value => (@site.footer_translations[locale] %> + <%= f.text_area locale, :class => "tinymce_textarea input-xxlarge", :value => (@site.footer_translations[locale] rescue nil) %> <% end %>

<%= (t 'admin.site_footer_help').html_safe %>

@@ -67,7 +66,7 @@
<%= f.fields_for :sub_menu_translations do |f| %> - <%= f.text_area locale, :class => "tinymce_textarea input-xxlarge", :value => (@site.sub_menu_translations[locale] %> + <%= f.text_area locale, :class => "tinymce_textarea input-xxlarge", :value => (@site.sub_menu_translations[locale] rescue nil) %> <% end %>