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

#createObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/lotus_admin/resource_controller.rb', line 24

def create
  self.resource = build_resource(permitted_params)

  authorize(resource) if using_pundit?

  if resource.save
    redirect_to after_create_redirect, notice: "Created new #{ resource_class.model_name.human } successfully"
  else
    render :new
  end
end

#destroyObject



60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/lotus_admin/resource_controller.rb', line 60

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

#index(&block) ⇒ Object



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

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

  respond_to do |format|
    format.html

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

#newObject



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

def new
  self.resource = build_resource

  authorize(resource) if using_pundit?
end

#showObject



56
57
58
# File 'app/controllers/lotus_admin/resource_controller.rb', line 56

def show
  authorize(resource) if using_pundit?
end

#updateObject



36
37
38
39
40
41
42
43
44
# File 'app/controllers/lotus_admin/resource_controller.rb', line 36

def update
  authorize(resource) if using_pundit?

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