Class: SolidusAdmin::AdjustmentReasonsController

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

Instance Method Summary collapse

Methods included from ComponentsHelper

#component

Instance Method Details

#createObject



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

def create
  @adjustment_reason = Spree::AdjustmentReason.new(adjustment_reason_params)

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

      format.html do
        redirect_to solidus_admin.adjustment_reasons_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('adjustment_reasons/new').new(page: @page, adjustment_reason: @adjustment_reason)
        render page_component, status: :unprocessable_entity
      end
    end
  end
end

#destroyObject



87
88
89
90
91
92
93
94
# File 'app/controllers/solidus_admin/adjustment_reasons_controller.rb', line 87

def destroy
  @adjustment_reason = Spree::AdjustmentReason.find_by!(id: params[:id])

  Spree::AdjustmentReason.transaction { @adjustment_reason.destroy }

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

#editObject



54
55
56
57
58
59
60
# File 'app/controllers/solidus_admin/adjustment_reasons_controller.rb', line 54

def edit
  set_index_page

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

#indexObject



9
10
11
12
13
14
15
# File 'app/controllers/solidus_admin/adjustment_reasons_controller.rb', line 9

def index
  set_index_page

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

#newObject



17
18
19
20
21
22
23
24
25
# File 'app/controllers/solidus_admin/adjustment_reasons_controller.rb', line 17

def new
  @adjustment_reason = Spree::AdjustmentReason.new

  set_index_page

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

#updateObject



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

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

      format.html do
        redirect_to solidus_admin.adjustment_reasons_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('adjustment_reasons/edit').new(page: @page, adjustment_reason: @adjustment_reason)
        render page_component, status: :unprocessable_entity
      end
    end
  end
end