diff --git a/app/controllers/admin/site_customization/information_texts_controller.rb b/app/controllers/admin/site_customization/information_texts_controller.rb index 6a8ecc1f3..31fc5f5a9 100644 --- a/app/controllers/admin/site_customization/information_texts_controller.rb +++ b/app/controllers/admin/site_customization/information_texts_controller.rb @@ -2,22 +2,8 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz include Translatable def index - existing_keys = {} - @tab = params[:tab] || :debates - - I18nContent.begins_with_key(@tab) - .all - .map{ |content| existing_keys[content.key] = content } - - @content = {} - - I18n.backend.send(:translations)[:en].each do |k,v| - @content[k.to_s] = flat_hash(v).keys - .map{ |s| existing_keys["#{k.to_s}.#{s}"].nil? ? - I18nContent.new(key: "#{k.to_s}.#{s}") : - existing_keys["#{k.to_s}.#{s}"] } - end - + fetch_existing_keys + append_or_create_keys @content = @content[@tab.to_s] end @@ -60,6 +46,26 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz end end + def fetch_existing_keys + existing_keys = {} + @tab = params[:tab] || :debates + + I18nContent.begins_with_key(@tab) + .all + .map{ |content| existing_keys[content.key] = content } + end + + def append_or_create_keys + @content = {} + + I18n.backend.send(:translations)[:en].each do |k, v| + @content[k.to_s] = flat_hash(v).keys + .map{ |s| existing_keys["#{k.to_s}.#{s}"].nil? ? + I18nContent.new(key: "#{k.to_s}.#{s}") : + existing_keys["#{k.to_s}.#{s}"] } + end + end + def flat_hash(h, f = nil, g = {}) return g.update({ f => h }) unless h.is_a? Hash h.each { |k, r| flat_hash(r, [f,k].compact.join('.'), g) }