1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2026-01-26 18:18:51 +01:00

Add status to translations

This commit is contained in:
2019-02-02 13:09:01 +01:00
parent 1533431c4a
commit 8da1323fd8
7 changed files with 22 additions and 14 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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