docbrown/app/controllers/admin/navigation_links_controller.rb
Arit Amana 3adfe7ace3
Static Sections for Site Navigation - Pt1 (#14213)
* schema file undelete description

* update with main

* update with origin

* Add "section" enum to navlink model

* create migration for section column

* create migration and data-update script

* update related rake tasks

* add scopes for default_links and other_links

* update E2E seeds

* ran migration; correct enum reference

* fix requests and model specs

* write DUS spec; fix factory and DUS

* yarn install

* address PR review comments

* fix migration; add null: false

* Remove yarn.lock from commit

* remove yarn.lock changes from commit

* sync yarn.lock with main

* newline
2021-07-14 11:01:56 -04:00

49 lines
1.5 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
@navigation_links = NavigationLink.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