Class: Lolita::RestController

Inherits:
ApplicationController
  • Object
show all
Includes:
ControllerAdditions, Hooks
Defined in:
app/controllers/lolita/rest_controller.rb

Instance Method Summary collapse

Methods included from Hooks

included, method_missing

Methods included from ControllerAdditions

included

Instance Method Details

#createObject



19
20
21
22
23
24
# File 'app/controllers/lolita/rest_controller.rb', line 19

def create
  self.run(:before_create)
  authorization_proxy.authorize!(:create,self.resource_class)
  build_resource
  save_and_redirect
end

#destroyObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/lolita/rest_controller.rb', line 44

def destroy
  self.run(:before_destroy)
  get_resource
  authorization_proxy.authorize!(:destroy, self.resource)
  if self.resource && self.resource.destroy
    flash[:notice] = ::I18n.t "lolita.shared.destroy_notice"
  else
    flash[:alert] = ::I18n.t "lolita.shared.destroy_alert"
  end
  self.run(:after_destroy)
  redirect_to lolita_resources_path
end

#editObject



26
27
28
29
30
31
# File 'app/controllers/lolita/rest_controller.rb', line 26

def edit
  self.run(:before_edit)
  get_resource
  authorization_proxy.authorize!(:update,self.resource)
  show_form
end

#indexObject



57
58
59
60
61
62
# File 'app/controllers/lolita/rest_controller.rb', line 57

def index
  self.run(:before_index)
  authorization_proxy.authorize!(:read,self.resource_class)
  show_index
  self.run(:after_index)
end

#newObject



12
13
14
15
16
17
# File 'app/controllers/lolita/rest_controller.rb', line 12

def new
  self.run(:before_new)
  authorization_proxy.authorize!(:create,self.resource_class)
  build_resource
  show_form
end

#updateObject



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/lolita/rest_controller.rb', line 33

def update
  self.run(:before_update)
  get_resource
  authorization_proxy.authorize!(:update,self.resource)
  if self.resource
    self.resource=resource_with_attributes(self.resource,resource_attributes)
    save_and_redirect

  end
end