Class: MenusController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/menus_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @menu = Menu.new(menu_params)
  if @menu.save
    redirect_to menus_path, notice: t('menus.create.notice')
  else
    render action: "new", warning: t('menus.create.warning'), layout: 'admin'
  end
end

#destroyObject



39
40
41
42
43
# File 'app/controllers/menus_controller.rb', line 39

def destroy
  @menu = Menu.find(params[:id])
  @menu.destroy
  redirect_to menus_url, notice: t('menus.destroy.notice')
end

#editObject



16
17
18
19
# File 'app/controllers/menus_controller.rb', line 16

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

#indexObject



6
7
8
9
# File 'app/controllers/menus_controller.rb', line 6

def index
  @menus = Menu.ordered
  switch_to_admin_layout
end

#newObject



11
12
13
14
# File 'app/controllers/menus_controller.rb', line 11

def new
  @menu = Menu.new
  switch_to_admin_layout
end

#reorderObject



45
46
47
48
49
# File 'app/controllers/menus_controller.rb', line 45

def reorder
  menu = Menu.find(params[:id])
  @menus = menu.self_and_siblings.ordered
  switch_to_admin_layout
end

#sortObject



51
52
53
54
55
56
# File 'app/controllers/menus_controller.rb', line 51

def sort
  params[:menu].each_with_index do |id, index|
    Menu.update(id, position: index+1)
  end
  render nothing: true
end

#updateObject



30
31
32
33
34
35
36
37
# File 'app/controllers/menus_controller.rb', line 30

def update
  @menu = Menu.find(params[:id])
  if @menu.update(menu_params)
    redirect_to menus_path, notice: t('menus.update.notice')
  else
    render action: "edit", warning: t('menus.update.warning'), layout: 'admin'
  end
end