Module: TypicalSituation::Actions

Defined in:
lib/typical_situation/actions.rb

Overview

Standard REST/CRUD actions.

Instance Method Summary collapse

Instance Method Details

#createObject



50
51
52
53
54
55
# File 'lib/typical_situation/actions.rb', line 50

def create
  raise TypicalSituation::ActionForbidden unless authorized?(:create)

  @resource = create_resource(create_params)
  respond_as_created
end

#destroyObject



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

def destroy
  get_resource
  raise TypicalSituation::ActionForbidden unless authorized?(:destroy, @resource)

  destroy_resource(@resource)
  respond_as_gone
end

#editObject



20
21
22
23
24
25
# File 'lib/typical_situation/actions.rb', line 20

def edit
  get_resource
  raise TypicalSituation::ActionForbidden unless authorized?(:edit, @resource)

  respond_with_resource
end

#indexObject



6
7
8
9
10
11
# File 'lib/typical_situation/actions.rb', line 6

def index
  raise TypicalSituation::ActionForbidden unless authorized?(:index)

  get_resources
  respond_with_resources
end

#newObject



27
28
29
30
31
32
# File 'lib/typical_situation/actions.rb', line 27

def new
  raise TypicalSituation::ActionForbidden unless authorized?(:new)

  new_resource
  respond_with_resource
end

#showObject



13
14
15
16
17
18
# File 'lib/typical_situation/actions.rb', line 13

def show
  get_resource
  raise TypicalSituation::ActionForbidden unless authorized?(:show, @resource)

  respond_with_resource
end

#updateObject



34
35
36
37
38
39
40
# File 'lib/typical_situation/actions.rb', line 34

def update
  get_resource
  raise TypicalSituation::ActionForbidden unless authorized?(:update, @resource)

  update_resource(@resource, update_params)
  respond_as_changed
end