Class: Wallaby::ResourcesController

Inherits:
CoreController show all
Defined in:
app/controllers/wallaby/resources_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CoreController

#status

Methods inherited from ApplicationController

#not_found, #unprocessable_entity

Class Method Details

.model_classObject



11
12
13
14
15
# File 'app/controllers/wallaby/resources_controller.rb', line 11

def self.model_class
  if self < Wallaby::ResourcesController
    Wallaby::Utils.to_model_class name.gsub('Controller', ''), name
  end
end

.resources_nameObject



5
6
7
8
9
# File 'app/controllers/wallaby/resources_controller.rb', line 5

def self.resources_name
  if self < Wallaby::ResourcesController
    Wallaby::Utils.to_resources_name name.gsub('Controller', '')
  end
end

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/wallaby/resources_controller.rb', line 26

def create
  authorize! :create, current_model_class
  @resource, is_success = current_model_service.create params, current_ability
  if is_success
    redirect_to resources_index_path, notice: 'successfully created'
  else
    flash.now[:error] = 'failed to create'
    render :new
  end
end

#destroyObject



56
57
58
59
60
61
62
63
# File 'app/controllers/wallaby/resources_controller.rb', line 56

def destroy
  authorize! :destroy, resource
  if current_model_service.destroy resource, params
    redirect_to resources_index_path, notice: 'successfully destroyed'
  else
    redirect_to resources_show_path, error: 'failed to destroy'
  end
end

#editObject



41
42
43
# File 'app/controllers/wallaby/resources_controller.rb', line 41

def edit
  authorize! :edit, resource
end

#indexObject



17
18
19
20
# File 'app/controllers/wallaby/resources_controller.rb', line 17

def index
  authorize! :index, current_model_class
  collection
end

#newObject



22
23
24
# File 'app/controllers/wallaby/resources_controller.rb', line 22

def new
  authorize! :new, new_resource
end

#showObject



37
38
39
# File 'app/controllers/wallaby/resources_controller.rb', line 37

def show
  authorize! :show, resource
end

#updateObject



45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/wallaby/resources_controller.rb', line 45

def update
  authorize! :update, resource
  @resource, is_success = current_model_service.update resource, params, current_ability
  if is_success
    redirect_to resources_show_path, notice: 'successfully updated'
  else
    flash.now[:error] = 'failed to update'
    render :edit
  end
end