diff --git a/app/controllers/translations_controller.rb b/app/controllers/translations_controller.rb index f3b0e70..25a0eab 100644 --- a/app/controllers/translations_controller.rb +++ b/app/controllers/translations_controller.rb @@ -11,18 +11,12 @@ class TranslationsController < ApplicationController end # POST /translations - # POST /translations.json def create @translation = @problem.translations.new(translation_params) - - respond_to do |format| - if @translation.save - format.html { redirect_to @problem, notice: t('translations.notice.successfully_created') } - format.json { render :show, status: :created, location: @translation } - else - format.html { render :new } - format.json { render json: @translation.errors, status: :unprocessable_entity } - end + if @translation.save + redirect_to @problem, notice: t('translations.notice.successfully_created') + else + render :new end end diff --git a/app/models/problem.rb b/app/models/problem.rb index a6ba173..e281d17 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -11,6 +11,14 @@ class Problem < ApplicationRecord !!self.translation end + def set_translation(translation) + if self.is_translated? + self.translation.outdated! + end + self.translation = translation + self.translation.in_use! + end + def original_url "https://projecteuler.net/problem=#{self.id}" end diff --git a/app/models/translation.rb b/app/models/translation.rb index e4695b6..35be7a1 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -1,5 +1,6 @@ class Translation < ApplicationRecord belongs_to :problem, inverse_of: :translations + enum status: [:pending, :in_use, :outdated, :declined] validates :title, :content, :problem_id, presence: true validate :title_is_unique_among_other_problems diff --git a/config/locales/views/application/de.yml b/config/locales/views/application/de.yml index 2340f66..550a87e 100644 --- a/config/locales/views/application/de.yml +++ b/config/locales/views/application/de.yml @@ -8,4 +8,8 @@ de: info: "Info" legal: "Impressum" copyright: "Copyright-Informationen" - bootstrap_html: 'Entworfen mit Bootstrap' \ No newline at end of file + bootstrap_html: 'Entworfen mit Bootstrap' + helpers: + submit: + translation: + create: "%{model} vorschlagen" diff --git a/config/locales/views/translations/de.yml b/config/locales/views/translations/de.yml index 69ea5f2..df84c5e 100644 --- a/config/locales/views/translations/de.yml +++ b/config/locales/views/translations/de.yml @@ -9,4 +9,4 @@ de: new: new_translation: Neue Übersetzung für Problem %{id} notice: - successfully_created: Übersetzung wurde erfolgreich erstellt. \ No newline at end of file + successfully_created: Der Übersetzungsvorschlag wurde eingereicht. Ein Organisator wird sich Ihren Vorschlag so bald wie möglich anschauen. \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 3475fce..f50f95e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150131103802) do +ActiveRecord::Schema.define(version: 2019_02_02_113250) do create_table "admins", force: :cascade do |t| t.string "email", default: "", null: false @@ -42,6 +42,7 @@ ActiveRecord::Schema.define(version: 20150131103802) do t.datetime "created_at" t.datetime "updated_at" t.integer "problem_id" + t.integer "status", default: 0 t.index ["problem_id"], name: "index_translations_on_problem_id" end diff --git a/db/seeds.rb b/db/seeds.rb index 452dab4..0986997 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -27,7 +27,7 @@ for i in 1..10 do ) problem = Problem.find(i) - problem.translation = translation + problem.set_translation(translation) problem.save! end