Class: Guts::NavigationItemsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Guts::NavigationItemsController
- Defined in:
- app/controllers/guts/navigation_items_controller.rb
Overview
Navigation Items controller
Instance Method Summary collapse
-
#create ⇒ Object
Creates a navigation item through post.
-
#destroy ⇒ Object
Destroys a single navigation item.
-
#edit ⇒ Object
Editing of a navigation item.
-
#index ⇒ Object
Displays a list of navigation items.
-
#navigatable_objects ⇒ Object
Generates a list of navigatable objects from the model provided.
-
#new ⇒ Object
Creation of a new navigation item.
-
#show ⇒ Object
Shows a single navigation item.
-
#update ⇒ Object
Updates a navigation item through patch.
Instance Method Details
#create ⇒ Object
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 43 |
# File 'app/controllers/guts/navigation_items_controller.rb', line 33 def create @navigation_item = NavigationItem.new @navigation_item if @navigation_item.save flash[:notice] = 'Navigation item was successfully created.' redirect_to (@navigation) else render :new end end |
#destroy ⇒ Object
Redirects to #index on success
Destroys a single navigation item
60 61 62 63 64 65 66 |
# File 'app/controllers/guts/navigation_items_controller.rb', line 60 def destroy @navigation_item @navigation_item.destroy flash[:notice] = 'Navigation item was successfully destroyed.' redirect_to (@navigation) end |
#edit ⇒ Object
Editing of a navigation item
27 28 29 |
# File 'app/controllers/guts/navigation_items_controller.rb', line 27 def edit @navigation_item end |
#index ⇒ Object
Displays a list of navigation items
11 12 13 |
# File 'app/controllers/guts/navigation_items_controller.rb', line 11 def index @navigation_items = @navigation.try(:navigation_items) || policy_scope(NavigationItem).all end |
#navigatable_objects ⇒ Object
Generates a list of navigatable objects from the model provided
71 72 73 74 75 76 77 |
# File 'app/controllers/guts/navigation_items_controller.rb', line 71 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 |
#new ⇒ Object
Creation of a new navigation item
21 22 23 24 |
# File 'app/controllers/guts/navigation_items_controller.rb', line 21 def new @navigation_item = NavigationItem.new @navigation_item end |
#show ⇒ Object
Shows a single navigation item
16 17 18 |
# File 'app/controllers/guts/navigation_items_controller.rb', line 16 def show @navigation_item end |
#update ⇒ Object
Redirects to #index if successfull or re-renders #edit if not
Updates a navigation item through patch
47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/guts/navigation_items_controller.rb', line 47 def update @navigation_item if @navigation_item.update flash[:notice] = 'Navigation item was successfully updated.' redirect_to (@navigation) else render :edit end end |