Sha256: bf1381f9764247351b1ebf751f6a67472b103ebd165c3d06ba495f850d05bebc

Contents?: true

Size: 1.52 KB

Versions: 10

Compression:

Stored size: 1.52 KB

Contents

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

        register_instance_option :member do
          true
        end

        register_instance_option :http_methods do
          [:get, :put]
        end

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

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

            elsif request.put? # UPDATE
              sanitize_params_for!(request.xhr? ? :modal : :update)

              @object.set_attributes(params[@abstract_model.param_key])
              @authorization_adapter && @authorization_adapter.authorize(:update, @abstract_model, @object)
              changes = @object.changes
              if @object.save
                @auditing_adapter && @auditing_adapter.update_object(@object, @abstract_model, _current_user, changes)
                respond_to do |format|
                  format.html { redirect_to_on_success }
                  format.js { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
                end
              else
                handle_save_error :edit
              end

            end
          end
        end

        register_instance_option :link_icon do
          'icon-pencil'
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rails_admin-2.3.1 lib/rails_admin/config/actions/edit.rb
rails_admin-2.3.0 lib/rails_admin/config/actions/edit.rb
rails_admin-2.2.1 lib/rails_admin/config/actions/edit.rb
rails_admin-2.2.0 lib/rails_admin/config/actions/edit.rb
rails_admin-2.1.1 lib/rails_admin/config/actions/edit.rb
rails_admin-2.1.0 lib/rails_admin/config/actions/edit.rb
rails_admin-2.0.2 lib/rails_admin/config/actions/edit.rb
rails_admin-2.0.1 lib/rails_admin/config/actions/edit.rb
rails_admin-2.0.0 lib/rails_admin/config/actions/edit.rb
rails_admin-2.0.0.rc lib/rails_admin/config/actions/edit.rb