Module: InheritedResources::Actions

Defined in:
lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb

Overview

Holds all default actions for InheritedResouces.

Instance Method Summary collapse

Instance Method Details

#create(options = {}, &block) ⇒ Object Also known as: create!

POST /resources



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb', line 30

def create(options={}, &block)
  object = build_resource

  if create_resource(object)
    set_flash_message!(:notice, '{{resource_name}} was successfully created.')
    options[:location] ||= resource_url rescue nil
    respond_with_dual_blocks(object, options, true, block)
  else
    set_flash_message!(:error)
    respond_with_dual_blocks(object, options, false, block)
  end
end

#destroy(options = {}, &block) ⇒ Object Also known as: destroy!

DELETE /resources/1



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb', line 60

def destroy(options={}, &block)
  object = resource

  if destroy_resource(object)
    set_flash_message!(:notice, '{{resource_name}} was successfully destroyed.')
  else
    set_flash_message!(:error, '{{resource_name}} could not be destroyed.')
  end

  options[:location] ||= collection_url rescue nil
  respond_with_dual_blocks(object, options, nil, block)
end

#edit(&block) ⇒ Object Also known as: edit!

GET /resources/1/edit



24
25
26
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb', line 24

def edit(&block)
  respond_with(resource, &block)
end

#index(&block) ⇒ Object Also known as: index!

GET /resources



6
7
8
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb', line 6

def index(&block)
  respond_with(collection, &block)
end

#new(&block) ⇒ Object Also known as: new!

GET /resources/new



18
19
20
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb', line 18

def new(&block)
  respond_with(build_resource, &block)
end

#show(&block) ⇒ Object Also known as: show!

GET /resources/1



12
13
14
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb', line 12

def show(&block)
  respond_with(resource, &block)
end

#update(options = {}, &block) ⇒ Object Also known as: update!

PUT /resources/1



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/actions.rb', line 45

def update(options={}, &block)
  object = resource

  if update_resource(object, params[resource_instance_name])
    set_flash_message!(:notice, '{{resource_name}} was successfully updated.')
    options[:location] ||= resource_url rescue nil
    respond_with_dual_blocks(object, options, true, block)
  else
    set_flash_message!(:error)
    respond_with_dual_blocks(object, options, false, block)
  end
end