mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
Add status to translations
This commit is contained in:
parent
1533431c4a
commit
8da1323fd8
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -9,3 +9,7 @@ de:
|
||||
legal: "Impressum"
|
||||
copyright: "Copyright-Informationen"
|
||||
bootstrap_html: 'Entworfen mit <a href="http://getbootstrap.com/">Bootstrap</a>'
|
||||
helpers:
|
||||
submit:
|
||||
translation:
|
||||
create: "%{model} vorschlagen"
|
||||
|
||||
@ -9,4 +9,4 @@ de:
|
||||
new:
|
||||
new_translation: Neue Übersetzung für Problem %{id}
|
||||
notice:
|
||||
successfully_created: Übersetzung wurde erfolgreich erstellt.
|
||||
successfully_created: Der Übersetzungsvorschlag wurde eingereicht. Ein Organisator wird sich Ihren Vorschlag so bald wie möglich anschauen.
|
||||
@ -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
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ for i in 1..10 do
|
||||
)
|
||||
|
||||
problem = Problem.find(i)
|
||||
problem.translation = translation
|
||||
problem.set_translation(translation)
|
||||
problem.save!
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user