docbrown/app/controllers/admin/navigation_links_controller.rb
Ridhwana 66b14fc0bf
[deploy] Dynamic frontend for the sidebar navigation Items (#10754)
* feat: configure the frontend for sidebar nav links

* chore: add a comment

* changes to the admin interface

* feat: move the temporary task to be in the rake tasks and use it in the dev seeds

* feat: use the task in the rake seeds

* refactor: reuse the form across two modals

* refactor: use the form partial

* feat: change the modal to be large

* fix: naming

* Update db/seeds.rb

Co-authored-by: Michael Kohl <me@citizen428.net>

* chore: make the file readable

* chore: removed the if else as the rake task was run on all forems + i sent out a message to new communities

* oops

* refactor: add a scope

* chore: oops removed this

* feat: add navigation links specs

* spec: fix two failing ones

Co-authored-by: Michael Kohl <me@citizen428.net>
2020-10-12 16:05:47 -04:00

48 lines
1.4 KiB
Ruby

module Admin
class NavigationLinksController < Admin::ApplicationController
ALLOWED_PARAMS = %i[
name url icon display_only_when_signed_in position
].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_url
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_url
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_url
end
private
def navigation_link_params
params.require(:navigation_link).permit(ALLOWED_PARAMS)
end
end
end