Class: Georgia::MenusController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability, #current_locale

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/georgia/menus_controller.rb', line 14

def create
  @menu = Menu.new(params[:menu])
  if @menu.save
    respond_to do |format|
      format.html { redirect_to [:edit, @menu], notice: "#{@menu.title} was successfully created." }
      format.js { render layout: false }
    end
  else
    respond_to do |format|
      format.html { render :edit }
      format.js { render layout: false }
    end
  end
end

#destroyObject



55
56
57
58
59
60
# File 'app/controllers/georgia/menus_controller.rb', line 55

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

  redirect_to menus_url
end

#editObject



33
34
35
36
# File 'app/controllers/georgia/menus_controller.rb', line 33

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

#indexObject



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

def index
  @menus = Menu.scoped.page(params[:page])
end

#newObject



10
11
12
# File 'app/controllers/georgia/menus_controller.rb', line 10

def new
  @menu = Menu.new
end

#showObject



29
30
31
# File 'app/controllers/georgia/menus_controller.rb', line 29

def show
  redirect_to edit_menu_path(params[:id])
end

#updateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/georgia/menus_controller.rb', line 38

def update
  @menu = Menu.find(params[:id])
  update_links_attributes(params[:menu].delete(:ancestry))
  update_links_menu_id
  if @menu.update_attributes(params[:menu])
    respond_to do |format|
      format.html { redirect_to [:edit, @menu], notice: "#{@menu.title} was successfully updated." }
      format.js { head :ok }
    end
  else
    respond_to do |format|
      format.html { render :edit, alert: "Oups. Something went wrong." }
      format.js { head :internal_server_error }
    end
  end
end