docbrown/app/controllers/admin/navigation_links_controller.rb
Arit Amana e589b11c77
Static Sections for Site Navigation - Pt2 (#14292)
* schema file undelete description

* update with main

* update with origin

* add sections in Admin

* Add "Section" radio btns to New-Link form

* Ensure links created in correct section

* Ensure links created in correct section pt2

* fix styling in admin

* complete section split on frontend

* start on specs

* complete specs

* remove unnecessary Cypress test file

* address all a11y comments in PR review

* fix broken specs due to a11y changes
2021-07-23 17:53:55 -04:00

50 lines
1.6 KiB
Ruby

module Admin
class NavigationLinksController < Admin::ApplicationController
after_action :bust_content_change_caches, only: %i[create update destroy]
ALLOWED_PARAMS = %i[
name url icon display_only_when_signed_in position section
].freeze
layout "admin"
def index
@default_nav_links = NavigationLink.default_section.ordered
@other_nav_links = NavigationLink.other_section.ordered
end
def create
navigation_link = NavigationLink.new(navigation_link_params)
if navigation_link.save
flash[:success] = "Successfully created navigation link: #{navigation_link.name}"
else
flash[:error] = "Error: #{navigation_link.errors_as_sentence}"
end
redirect_to admin_navigation_links_path
end
def update
navigation_link = NavigationLink.find(params[:id])
if navigation_link.update(navigation_link_params)
flash[:success] = "Successfully updated navigation link: #{navigation_link.name}"
else
flash[:error] = "Error: #{navigation_link.errors_as_sentence}"
end
redirect_to admin_navigation_links_path
end
def destroy
navigation_link = NavigationLink.find(params[:id])
if navigation_link.destroy
flash[:success] = "Navigation Link #{navigation_link.name} deleted"
else
flash[:error] = "Error: #{navigation_link.errors_as_sentence}"
end
redirect_to admin_navigation_links_path
end
private
def navigation_link_params
params.require(:navigation_link).permit(ALLOWED_PARAMS)
end
end
end