From 0bf90f17b68997ce24328c11ee8bc37d1fde5306 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 6 Aug 2013 10:18:50 +0200 Subject: [PATCH] Moved db access to model. --- app/controllers/translations_controller.rb | 25 ++-------------------- app/models/translation.rb | 23 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/controllers/translations_controller.rb b/app/controllers/translations_controller.rb index 9f72640a5..b33b0155a 100644 --- a/app/controllers/translations_controller.rb +++ b/app/controllers/translations_controller.rb @@ -5,28 +5,7 @@ class TranslationsController < ApplicationController # GET /translations/:lang def load - translations = Translation.where( :locale => params[:locale] ) - - list = [] - translations.each { |item| - data = [ - item.id, - item.source, - item.target, - ] - list.push data - } - - timestamp_map_default = 'yyyy-mm-dd HH:MM' - timestamp_map = { - :de => 'dd.mm.yyyy HH:MM', - } - timestamp = timestamp_map[ params[:locale].to_sym ] || timestamp_map_default - - render :json => { - :list => list, - :timestampFormat => timestamp, - } + render :json => Translation.list( params[:locale] ) end # GET /translations @@ -53,4 +32,4 @@ class TranslationsController < ApplicationController def destroy model_destory_render(Translation, params) end -end +end \ No newline at end of file diff --git a/app/models/translation.rb b/app/models/translation.rb index b62a195bd..62f661c3c 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -3,6 +3,29 @@ class Translation < ApplicationModel before_create :set_initial + def self.list(locale) + translations = Translation.where( :locale => locale ) + list = [] + translations.each { |item| + data = [ + item.id, + item.source, + item.target, + ] + list.push data + } + + timestamp_map_default = 'yyyy-mm-dd HH:MM' + timestamp_map = { + :de => 'dd.mm.yyyy HH:MM', + } + timestamp = timestamp_map[ locale.to_sym ] || timestamp_map_default + return { + :list => list, + :timestampFormat => timestamp, + } + end + def self.translate(locale, string) # translate string