Class: Guts::NavigationsController

Inherits:
ApplicationController show all
Includes:
ControllerPermissionConcern
Defined in:
app/controllers/guts/navigations_controller.rb

Overview

Navigations ontroller

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Methods included from MultisiteConcern

#current_site, #with_current_site

Instance Method Details

#createObject

Note:

Redirects to #index if successfull or re-renders #new if not

Creates a navigation through post



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/guts/navigations_controller.rb', line 31

def create
  @navigation = Navigation.new navigation_params

  if @navigation.save
    flash[:notice] = 'Navigation was successfully created.'
    redirect_to navigations_path
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a single navigation



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

def destroy
  @navigation.destroy

  flash[:notice] = 'Navigation was successfully destroyed.'
  redirect_to navigations_path
end

#editObject

Editing of a navigartion



26
27
# File 'app/controllers/guts/navigations_controller.rb', line 26

def edit
end

#indexObject

Displays a list of navigations



12
13
14
# File 'app/controllers/guts/navigations_controller.rb', line 12

def index
  @navigations = Navigation.all
end

#newObject

Creation of a new navigation



21
22
23
# File 'app/controllers/guts/navigations_controller.rb', line 21

def new
  @navigation = Navigation.new
end

#reorderObject

Note:

This is an AJAX call

Updates sorting for a navigation



64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/guts/navigations_controller.rb', line 64

def reorder
  ActiveRecord::Base.transaction do
    @navigation.navigation_items.each do |item|
      find = params[:order].select { |_, v| v == item.id.to_s }
      item.update_attribute(:position, find[0].to_i)
    end
  end

  head :ok
end

#showObject

Shows details about a single navigation



17
18
# File 'app/controllers/guts/navigations_controller.rb', line 17

def show
end

#updateObject

Note:

Redirects to #index if successfull or re-renders #edit if not

Updates a navigation through patch



44
45
46
47
48
49
50
51
# File 'app/controllers/guts/navigations_controller.rb', line 44

def update
  if @navigation.update(navigation_params)
    flash[:notice] = 'Navigation was successfully updated.'
    redirect_to navigations_path
  else
    render :edit
  end
end