Sha256: bf4311c1c6effc1b165795600baa1d57b74e7c49cd8bd96be51c06f02ad1dc84

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 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.new 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

              @cached_assocations_hash = associations_hash
              @attributes = get_attributes
              @modified_assoc = []

              @old_object = @object.dup
              @model_config.update.fields.map { |f| f.parse_input(@attributes) if f.respond_to?(:parse_input) }
              @object.set_attributes(@attributes, _attr_accessible_role)

              if @object.save
                @auditing_adapter && @auditing_adapter.update_object(@abstract_model, @object, @cached_assocations_hash, associations_hash, @modified_assoc, @old_object, _current_user)
                respond_to do |format|
                  format.html { redirect_to_on_success }
                  format.js { render :json => { :id => @object.id, :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

1 entries across 1 versions & 1 rubygems

Version Path
obitum-rails_admin-0.0.2 lib/rails_admin/config/actions/edit.rb