Class: LotusAdmin::ResourceController

Inherits:
AuthenticatedController show all
Defined in:
app/controllers/lotus_admin/resource_controller.rb

Direct Known Subclasses

UsersController

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.manages(model_class) ⇒ Object



8
9
10
# File 'app/controllers/lotus_admin/resource_controller.rb', line 8

def self.manages(model_class)
  self._resource_class = model_class
end

Instance Method Details

#create(&block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/lotus_admin/resource_controller.rb', line 26

def create(&block)
  self.resource = build_resource(permitted_params)

  authorize(resource) if using_pundit?

  respond_to do |format|
    format.html

    if block.present?
      block.call(format)
    else
      if resource.save
        redirect_to after_create_redirect, notice: "Created new #{ resource_class.model_name.human } successfully"
      else
        render :new
      end
    end
  end
end

#destroyObject



88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/lotus_admin/resource_controller.rb', line 88

def destroy
  authorize(resource) if using_pundit?

  if resource.destroy
    flash[:notice] = "#{ resource_class.model_name.human } has been removed"
  else
    flash[:error] = "There was an error removing that #{ resource_class.model_name.human }"
  end

  redirect_to after_destroy_redirect
end

#edit(&block) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'app/controllers/lotus_admin/resource_controller.rb', line 46

def edit(&block)
  authorize(resource) if using_pundit?

  if block.present?
    block.call
  else
    render :edit
  end
end

#index(&block) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'app/controllers/lotus_admin/resource_controller.rb', line 74

def index(&block)
  authorize(resource_class) if using_pundit?

  respond_to do |format|
    format.html

    block.call(format) if block.present?
  end
end

#new(&block) ⇒ Object



18
19
20
21
22
23
24
# File 'app/controllers/lotus_admin/resource_controller.rb', line 18

def new(&block)
  self.resource = build_resource

  authorize(resource) if using_pundit?

  block.call if block.present?
end

#showObject



84
85
86
# File 'app/controllers/lotus_admin/resource_controller.rb', line 84

def show
  authorize(resource) if using_pundit?
end

#update(&block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/lotus_admin/resource_controller.rb', line 56

def update(&block)
  authorize(resource) if using_pundit?

  respond_to do |format|
    format.html

    if block.present?
      block.call(format)
    else
      if resource.update(permitted_params)
        redirect_to after_update_redirect, notice: "Updated #{ resource_class.model_name.human } successfully"
      else
        render :edit
      end
    end
  end
end