Sha256: 03a280534ad2ce3d8b3c0c821f9927d730b5d4d00c4d15f6cd9cfeff45428b02

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Concerns
  module Backend
    module ContentTypeController
      extend ActiveSupport::Concern

      included do
        layout 'backend/lightbox'
        before_action :find_model
        helper_method :content_path
      end

      module ClassMethods
        def model(value)
          define_method(:model) { value }
        end

        def allowed_params(*args)
          define_method(:allowed_params) do
            params.require(model.name.tableize.singularize).permit(*args)
          end
        end
      end

      def find_model
        @model = model.find(params[:id]).decorate
      end

      # TODO refactor?
      def content_path
        column = @model.column
        path = "edit_translation_backend_#{column.row.rowable.class.to_s.downcase}_path"
        send(path, column.row.rowable, locale, anchor: "content-row-#{column.row.id}")
      end

      def update
        if @model.update_attributes allowed_params
          redirect_to content_path
        else
          render :edit
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
udongo-0.1.0 app/controllers/concerns/backend/content_type_controller.rb