Module: ActiveAdmin::ResourceController::Callbacks

Extended by:
ActiveSupport::Concern
Includes:
Callbacks
Defined in:
lib/active_admin/resource_controller/callbacks.rb

Instance Method Summary collapse

Methods included from Callbacks

#call_callback_with

Instance Method Details

#build_resourceObject (protected)



14
15
16
17
18
# File 'lib/active_admin/resource_controller/callbacks.rb', line 14

def build_resource
  object = super
  run_build_callbacks object
  object
end

#create_resource(object) ⇒ Object (protected)



20
21
22
23
24
# File 'lib/active_admin/resource_controller/callbacks.rb', line 20

def create_resource(object)
  run_create_callbacks object do
    save_resource(object)
  end
end

#destroy_resource(object) ⇒ Object (protected)



51
52
53
54
55
# File 'lib/active_admin/resource_controller/callbacks.rb', line 51

def destroy_resource(object)
  run_destroy_callbacks object do
    object.destroy
  end
end

#save_resource(object) ⇒ Object (protected)



26
27
28
29
30
# File 'lib/active_admin/resource_controller/callbacks.rb', line 26

def save_resource(object)
  run_save_callbacks object do
    object.save
  end
end

#update_resource(object, attributes) ⇒ Object (protected)



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/active_admin/resource_controller/callbacks.rb', line 32

def update_resource(object, attributes)
  # Inherited resources 1.3.0 calls the method passing an array instead of a parameters hash.
  # The array contains in the first position the parameters which update the object and in the second position
  # possibly contains the role, it's optional, to use in mass assignment. This feature is provided by Rails 3.1
  if attributes.is_a?(Array)
    if object.respond_to?(:assign_attributes)
      object.assign_attributes(*attributes)
    else
      object.attributes = attributes[0]
    end
  else
    object.attributes = attributes
  end

  run_update_callbacks object do
    save_resource(object)
  end
end