Class: SolidusAdmin::RolesController

Inherits:
BaseController
  • Object
show all
Includes:
ControllerHelpers::Search
Defined in:
app/controllers/solidus_admin/roles_controller.rb

Instance Method Summary collapse

Methods included from ComponentsHelper

#component

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/solidus_admin/roles_controller.rb', line 30

def create
  @role = Spree::Role.new(role_params)

  if @role.save
    respond_to do |format|
      flash[:notice] = t('.success')

      format.html do
        redirect_to solidus_admin.roles_path, status: :see_other
      end

      format.turbo_stream do
        render turbo_stream: '<turbo-stream action="refresh" />'
      end
    end
  else
    set_index_page

    respond_to do |format|
      format.html do
        page_component = component('roles/new').new(page: @page, role: @role)
        render page_component, status: :unprocessable_entity
      end
    end
  end
end

#destroyObject



90
91
92
93
94
95
96
97
# File 'app/controllers/solidus_admin/roles_controller.rb', line 90

def destroy
  @roles = Spree::Role.where(id: params[:id])

  Spree::Role.transaction { @roles.destroy_all }

  flash[:notice] = t('.success')
  redirect_back_or_to solidus_admin.roles_path, status: :see_other
end

#editObject



57
58
59
60
61
62
63
# File 'app/controllers/solidus_admin/roles_controller.rb', line 57

def edit
  set_index_page

  respond_to do |format|
    format.html { render component('roles/edit').new(page: @page, role: @role) }
  end
end

#indexObject



12
13
14
15
16
17
18
# File 'app/controllers/solidus_admin/roles_controller.rb', line 12

def index
  set_index_page

  respond_to do |format|
    format.html { render component('roles/index').new(page: @page) }
  end
end

#newObject



20
21
22
23
24
25
26
27
28
# File 'app/controllers/solidus_admin/roles_controller.rb', line 20

def new
  @role = Spree::Role.new

  set_index_page

  respond_to do |format|
    format.html { render component('roles/new').new(page: @page, role: @role) }
  end
end

#updateObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/solidus_admin/roles_controller.rb', line 65

def update
  if @role.update(role_params)
    respond_to do |format|
      flash[:notice] = t('.success')

      format.html do
        redirect_to solidus_admin.roles_path, status: :see_other
      end

      format.turbo_stream do
        render turbo_stream: '<turbo-stream action="refresh" />'
      end
    end
  else
    set_index_page

    respond_to do |format|
      format.html do
        page_component = component('roles/edit').new(page: @page, role: @role)
        render page_component, status: :unprocessable_entity
      end
    end
  end
end