Class: Guts::NavigationItemsController

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

Overview

Navigation Items controller

Instance Method Summary collapse

Methods included from SessionsHelper

#current_user, #log_in, #log_out, #logged_in?

Instance Method Details

#createObject

Note:

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

Creates a navigation item through post



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

def create
  @navigation_item = NavigationItem.new navigation_item_params

  if @navigation_item.save
    redirect_to navigation_navigation_items_path(@navigation), notice: "Navigation item was successfully created."
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a single navigation item



52
53
54
55
# File 'app/controllers/guts/navigation_items_controller.rb', line 52

def destroy
  @navigation_item.destroy
  redirect_to navigation_navigation_items_path(@navigation), notice: "Navigation item was successfully destroyed."
end

#editObject

Editing of a navigation item



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

def edit
end

#indexObject

Displays a list of navigation items



11
12
13
# File 'app/controllers/guts/navigation_items_controller.rb', line 11

def index
  @navigation_items = NavigationItem.all
end

Generates a list of navigatable objects from the model provided

Returns:

  • (Object)

    JSON of navigatable objects

See Also:



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

def navigatable_objects
  model   = params[:model].constantize
  objects = model.all.map {|obj| {id: obj.id, format: obj.navigatable_format}} if @navigatable.map {|m| m[:name]}.include?(params[:model])
  render json: objects
end

#newObject

Creation of a new navigation item



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

def new
  @navigation_item = NavigationItem.new
end

#showObject

Shows a single navigation item



16
17
# File 'app/controllers/guts/navigation_items_controller.rb', line 16

def show
end

#updateObject

Note:

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

Updates a navigation item through patch



42
43
44
45
46
47
48
# File 'app/controllers/guts/navigation_items_controller.rb', line 42

def update
  if @navigation_item.update navigation_item_params
    redirect_to navigation_navigation_items_path(@navigation), notice: "Navigation item was successfully updated."
  else
    render :edit
  end
end