Class: SolidusAdmin::TaxCategoriesController

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

Instance Method Summary collapse

Methods included from ComponentsHelper

#component

Instance Method Details

#createObject



29
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
56
# File 'app/controllers/solidus_admin/tax_categories_controller.rb', line 29

def create
  @tax_category = Spree::TaxCategory.new(tax_category_params)

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

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

      format.turbo_stream do
        # we need to explicitly write the refresh tag for now.
        # See https://github.com/hotwired/turbo-rails/issues/579
        render turbo_stream: '<turbo-stream action="refresh" />'
      end
    end
  else
    set_index_page

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

#destroyObject



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

def destroy
  @tax_categories = Spree::TaxCategory.where(id: params[:id])

  Spree::TaxCategory.transaction { @tax_categories.destroy_all }

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

#editObject



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

def edit
  @tax_category = Spree::TaxCategory.find(params[:id])

  set_index_page

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

#indexObject



83
84
85
86
87
88
89
# File 'app/controllers/solidus_admin/tax_categories_controller.rb', line 83

def index
  set_index_page

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

#newObject



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

def new
  @tax_category = Spree::TaxCategory.new

  set_index_page

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

#updateObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/solidus_admin/tax_categories_controller.rb', line 58

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

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