Sha256: a867f2734313f8497c2a465ff0b3aba3f04704639c1004abf2ec6fbb192e8b8e

Contents?: true

Size: 1006 Bytes

Versions: 7

Compression:

Stored size: 1006 Bytes

Contents

module Concerns
  module Backend
    module TranslatableController
      extend ActiveSupport::Concern

      included do
        before_action :find_models, only: [:edit_translation, :update_translation]
        helper_method :translatable_path
      end

      def update_translation
        if @translation.validate(params[model_name])
          @translation.save
          redirect_to translatable_path, notice: t('b.msg.changes_saved')
        else
          render :edit_translation
        end
      end

      private

      def find_models
        @model ||= find_model
        @translation = translation_form
      end

      def model_name
        @model.class.to_s.underscore.gsub('_decorator', '')
      end

      def set_translatable_path(path)
        @translatable_path ||= path
      end

      def translatable_path
        method = "edit_translation_backend_#{model_name}_path"
        @translatable_path || send(method, @model, params[:translation_locale])
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
udongo-2.0.0 app/controllers/concerns/backend/translatable_controller.rb
udongo-1.0.4 app/controllers/concerns/backend/translatable_controller.rb
udongo-1.0.3 app/controllers/concerns/backend/translatable_controller.rb
udongo-1.0.2 app/controllers/concerns/backend/translatable_controller.rb
udongo-1.0.1 app/controllers/concerns/backend/translatable_controller.rb
udongo-1.0.0 app/controllers/concerns/backend/translatable_controller.rb
udongo-0.1.0 app/controllers/concerns/backend/translatable_controller.rb