Sha256: 2b58681aa2e4b147394109a817ac76201df54c01dd64806d67dfde6424c4c015

Contents?: true

Size: 1.47 KB

Versions: 12

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module RailsAdmin
  module Config
    module Actions
      class Delete < RailsAdmin::Config::Actions::Base
        RailsAdmin::Config::Actions.register(self)

        register_instance_option :member do
          true
        end

        register_instance_option :route_fragment do
          'delete'
        end

        register_instance_option :http_methods do
          %i[get delete]
        end

        register_instance_option :authorization_key do
          :destroy
        end

        register_instance_option :controller do
          proc do
            if request.get? # DELETE

              respond_to do |format|
                format.html { render @action.template_name }
                format.js   { render @action.template_name, layout: false }
              end

            elsif request.delete? # DESTROY

              @auditing_adapter&.delete_object(@object, @abstract_model, _current_user)
              if @object.destroy
                flash[:success] = t('admin.flash.successful', name: @model_config.label, action: t('admin.actions.delete.done'))
                redirect_to index_path
              else
                handle_save_error :delete
              end

            end
          end
        end

        register_instance_option :link_icon do
          'fas fa-times'
        end

        register_instance_option :writable? do
          !(bindings[:object] && bindings[:object].readonly?)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rails_admin-3.2.1 lib/rails_admin/config/actions/delete.rb
rails_admin-3.2.0 lib/rails_admin/config/actions/delete.rb
rails_admin-3.2.0.rc lib/rails_admin/config/actions/delete.rb
rails_admin-3.2.0.beta lib/rails_admin/config/actions/delete.rb
rails_admin-3.1.4 lib/rails_admin/config/actions/delete.rb
rails_admin-3.1.3 lib/rails_admin/config/actions/delete.rb
rails_admin-3.1.2 lib/rails_admin/config/actions/delete.rb
rails_admin-3.1.1 lib/rails_admin/config/actions/delete.rb
rails_admin-3.1.0 lib/rails_admin/config/actions/delete.rb
rails_admin-3.1.0.rc2 lib/rails_admin/config/actions/delete.rb
rails_admin-3.1.0.rc lib/rails_admin/config/actions/delete.rb
rails_admin-3.1.0.beta lib/rails_admin/config/actions/delete.rb