Class: SolidusAdmin::StoreCreditReasonsController

Inherits:
BaseController
  • Object
show all
Includes:
ControllerHelpers::Search
Defined in:
app/controllers/solidus_admin/store_credit_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/store_credit_reasons_controller.rb', line 27

def create
  @store_credit_reason = Spree::StoreCreditReason.new(store_credit_reason_params)

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

      format.html do
        redirect_to solidus_admin.store_credit_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('store_credit_reasons/new').new(page: @page, store_credit_reason: @store_credit_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/store_credit_reasons_controller.rb', line 87

def destroy
  @store_credit_reason = Spree::StoreCreditReason.find_by!(id: params[:id])

  Spree::StoreCreditReason.transaction { @store_credit_reason.destroy }

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

#editObject



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

def edit
  set_index_page

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

#indexObject



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

def index
  set_index_page

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

#newObject



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

def new
  @store_credit_reason = Spree::StoreCreditReason.new

  set_index_page

  respond_to do |format|
    format.html { render component('store_credit_reasons/new').new(page: @page, store_credit_reason: @store_credit_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/store_credit_reasons_controller.rb', line 62

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

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