Class: Guts::NavigationsController

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

Overview

Navigations ontroller

Instance Method Summary collapse

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
41
# File 'app/controllers/guts/navigations_controller.rb', line 31

def create
  @navigation = Navigation.new navigation_params
  authorize @navigation

  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



58
59
60
61
62
63
64
# File 'app/controllers/guts/navigations_controller.rb', line 58

def destroy
  authorize @navigation
  @navigation.destroy

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

#editObject

Editing of a navigartion



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

def edit
  authorize @navigation
end

#indexObject

Displays a list of navigations



9
10
11
# File 'app/controllers/guts/navigations_controller.rb', line 9

def index
  @navigations = policy_scope(Navigation).all
end

#newObject

Creation of a new navigation



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

def new
  @navigation = Navigation.new
  authorize @navigation
end

#reorderObject

Note:

This is an AJAX call

Updates sorting for a navigation



68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/guts/navigations_controller.rb', line 68

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

  head :ok
end

#showObject

Shows details about a single navigation



14
15
16
# File 'app/controllers/guts/navigations_controller.rb', line 14

def show
  authorize @navigation
end

#updateObject

Note:

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

Updates a navigation through patch



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

def update
  authorize @navigation

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