Class: Guts::NavigationItemsController

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

Overview

Navigation Items controller

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 item through post



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/guts/navigation_items_controller.rb', line 33

def create
  @navigation_item = NavigationItem.new navigation_item_params

  if @navigation_item.save
    flash[:notice] = 'Navigation item was successfully created.'
    redirect_to navigation_navigation_items_path(@navigation)
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a single navigation item



57
58
59
60
61
62
# File 'app/controllers/guts/navigation_items_controller.rb', line 57

def destroy
  @navigation_item.destroy

  flash[:notice] = 'Navigation item was successfully destroyed.'
  redirect_to navigation_navigation_items_path(@navigation)
end

#editObject

Editing of a navigation item



28
29
# File 'app/controllers/guts/navigation_items_controller.rb', line 28

def edit
end

#indexObject

Displays a list of navigation items



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

def index
  @navigation_items = @navigation.try(:navigation_items) || NavigationItem.all
end

Generates a list of navigatable objects from the model provided

Returns:

  • (Object)

    JSON of navigatable objects

See Also:



67
68
69
70
71
72
73
# File 'app/controllers/guts/navigation_items_controller.rb', line 67

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

  render json: objects
end

#newObject

Creation of a new navigation item



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

def new
  @navigation_item = NavigationItem.new
end

#showObject

Shows a single navigation item



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

def show
end

#updateObject

Note:

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

Updates a navigation item through patch



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

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