Sha256: feb0dfbca3a745be03a463fc76e5b1695a7989b39ee7ccbb3c7cf77cd23e2e61

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

module Alchemy
  module Custom
    module Model
      module Admin
        class ClonesController < ::Alchemy::Custom::Model::Admin::BaseController
          def create
            @obj.assign_attributes clean_params
            if @parent.present? and @obj.respond_to?("#{parent_model_name_demodulized}=".to_sym)
              @obj.send "#{parent_model_name_demodulized}=", @parent
            end
            @obj = yield @obj if block_given?
            if @obj.apply
              after_successfull_create
            else
              after_unsuccessfully_create
            end
          end

          private

          def authorize_resource
            authorize!(:clone, @parent.class)
          end

          def base_class
            "::#{parent_model_name_demodulized.classify}Cloner".constantize
          end

          def after_successfull_create
            url = polymorphic_path [:admin, @parent.class]
            flash[:notice] = t(:record_succesfully_cloned, model: @parent.class.model_name.human)
            respond_to do |format|
              format.js {
                @redirect_url = url
                render :redirect
              }
              format.html {redirect_to url}
            end
          end

          def after_unsuccessfully_create
            render :new
          end

          def permitted_attributes
            base_class._virtual_column_names.collect(&:to_sym)
          end


        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alchemy-custom-model-2.0.1 app/controllers/alchemy/custom/model/admin/clones_controller.rb
alchemy-custom-model-2.0.0 app/controllers/alchemy/custom/model/admin/clones_controller.rb
alchemy-custom-model-0.1.9 app/controllers/alchemy/custom/model/admin/clones_controller.rb