Files
nairobi/app/controllers/remote_translations_controller.rb
taitus 744a3d48fd Create RemoteTranslations Controller
- Create RemoteTranslations Controller to receive resources without
  translations and create RemoteTranslation instances when theirs
  translations are not enqueued.
- Create remote_translation_enqueued? class method on RemoteTranslation
  model to check if exists same remote translations without errors
  pending to translate.
2019-06-27 09:21:18 +02:00

33 lines
1.0 KiB
Ruby

class RemoteTranslationsController < ApplicationController
skip_authorization_check
respond_to :html, :js
before_action :set_remote_translations, only: :create
def create
@remote_translations.each do |remote_translation|
RemoteTranslation.create(remote_translation) unless translations_enqueued?(remote_translation)
end
redirect_to request.referer, notice: t('remote_translations.create.enqueue_remote_translation')
end
private
def remote_translations_params
params.permit(:remote_translations)
end
def set_remote_translations
decoded_remote_translations = ActiveSupport::JSON.decode(remote_translations_params["remote_translations"])
@remote_translations = decoded_remote_translations.map{ |remote_translation|
remote_translation.slice("remote_translatable_id","remote_translatable_type","locale")
}
end
def translations_enqueued?(remote_translation)
RemoteTranslation.remote_translation_enqueued?(remote_translation)
end
end