Module: InheritedResources::Actions

Defined in:
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
# File 'lib/inherited_resources/actions.rb', line 30

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

  if create_resource(object)
    options[:location] ||= smart_resource_url
  end

  respond_with_dual_blocks(object, options, &block)
end

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

DELETE /resources/1



54
55
56
57
58
59
60
# File 'lib/inherited_resources/actions.rb', line 54

def destroy(options={}, &block)
  object = resource
  options[:location] ||= smart_collection_url

  destroy_resource(object)
  respond_with_dual_blocks(object, options, &block)
end

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

GET /resources/1/edit



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

def edit(options={}, &block)
  respond_with(*(with_chain(resource) << options), &block)
end

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

GET /resources



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

def index(options={}, &block)
  respond_with(*(with_chain(collection) << options), &block)
end

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

GET /resources/new



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

def new(options={}, &block)
  respond_with(*(with_chain(build_resource) << options), &block)
end

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

GET /resources/1



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

def show(options={}, &block)
  respond_with(*(with_chain(resource) << options), &block)
end

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

PUT /resources/1



42
43
44
45
46
47
48
49
50
# File 'lib/inherited_resources/actions.rb', line 42

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

  if update_resource(object, resource_params)
    options[:location] ||= smart_resource_url
  end

  respond_with_dual_blocks(object, options, &block)
end