Class: Katalyst::Navigation::MenusController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/katalyst/navigation/menus_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



35
36
37
38
39
40
41
42
43
# File 'app/controllers/katalyst/navigation/menus_controller.rb', line 35

def create
  @menu = Menu.new(menu_params)

  if @menu.save
    redirect_to @menu
  else
    render :new, locals: { menu: @menu }, status: :unprocessable_entity
  end
end

#destroyObject



68
69
70
71
72
73
74
# File 'app/controllers/katalyst/navigation/menus_controller.rb', line 68

def destroy
  menu = Menu.find(params[:id])

  menu.destroy!

  redirect_to action: :index, status: :see_other
end

#editObject



29
30
31
32
33
# File 'app/controllers/katalyst/navigation/menus_controller.rb', line 29

def edit
  menu = Menu.find(params[:id])

  render locals: { menu: menu }
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/katalyst/navigation/menus_controller.rb', line 6

def index
  collection = Katalyst::Tables::Collection::Base.new(sorting: :title).with_params(params).apply(Menu.all)
  table      = Katalyst::Turbo::TableComponent.new(collection: collection,
                                                   id:         "index-table",
                                                   class:      "index-table",
                                                   caption:    true)

  respond_to do |format|
    format.turbo_stream { render(table) } if self_referred?
    format.html { render :index, locals: { table: table } }
  end
end

#newObject



25
26
27
# File 'app/controllers/katalyst/navigation/menus_controller.rb', line 25

def new
  render locals: { menu: Menu.new }
end

#showObject



19
20
21
22
23
# File 'app/controllers/katalyst/navigation/menus_controller.rb', line 19

def show
  menu = Menu.find(params[:id])

  render locals: { menu: menu }
end

#updateObject

PATCH /admins/navigation_menus/:slug



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/katalyst/navigation/menus_controller.rb', line 46

def update
  menu = Menu.find(params[:id])

  menu.attributes = menu_params

  unless menu.valid?
    return render turbo_stream: helpers.navigation_editor_errors(menu: menu),
                  status:       :unprocessable_entity
  end

  case params[:commit]
  when "publish"
    menu.save!
    menu.publish!
  when "save"
    menu.save!
  when "revert"
    menu.revert!
  end
  redirect_to menu
end