* feat: make the sidebar more dynamic * refactor: use the action in the same controller instead of the whole path * feat: remove hardcoded routes * feat: move routes into file * feat: use rails 6 draw for the admin routes * add a helper method * oops: fix super * feat: add the hacky helper methods :( ) * WIP: created different path helpers for the new routes and point the old helpers to the new ones if the FF is toggled * feat: update the module * chore: add new paths * feat: change link_to's use paths instead * feat: feedback_messages to scoped admin route * chore: update the feature flag urls helpers * feat: feedback_messages issue * chore: remove all the workarounds * chore: rubucop * fix: oops remove helper * chore: comment out the tests that touch the tabbed navbar which is affected by the rails application needing to be reloaded * feat: ensure that we chcek if the db table exists
67 lines
2.1 KiB
Ruby
67 lines
2.1 KiB
Ruby
module Admin
|
|
class ResponseTemplatesController < Admin::ApplicationController
|
|
layout "admin"
|
|
after_action only: %i[create update destroy] do
|
|
Audit::Logger.log(:moderator, current_user, params.dup)
|
|
end
|
|
|
|
def index
|
|
@response_templates = if params[:filter]
|
|
ResponseTemplate.where(type_of: params[:filter])
|
|
else
|
|
ResponseTemplate.all
|
|
end
|
|
@response_templates = @response_templates.page(params[:page]).per(50)
|
|
end
|
|
|
|
def new
|
|
@response_template = ResponseTemplate.new
|
|
end
|
|
|
|
def create
|
|
@response_template = ResponseTemplate.new(permitted_params)
|
|
if @response_template.save
|
|
flash[:success] = "Response Template: \"#{@response_template.title}\" saved successfully."
|
|
redirect_to admin_response_templates_path
|
|
else
|
|
flash[:danger] = @response_template.errors_as_sentence
|
|
@response_templates = ResponseTemplate.page(params[:page]).per(50)
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@response_template = ResponseTemplate.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
@response_template = ResponseTemplate.find(params[:id])
|
|
|
|
if @response_template.update(permitted_attributes(ResponseTemplate))
|
|
flash[:success] = "The response template \"#{@response_template.title}\" was updated."
|
|
redirect_to edit_admin_response_template_path(@response_template)
|
|
else
|
|
flash[:danger] = @response_template.errors_as_sentence
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@response_template = ResponseTemplate.find(params[:id])
|
|
|
|
if @response_template.destroy
|
|
flash[:success] = "The response template \"#{@response_template.title}\" was deleted."
|
|
else
|
|
flash[:danger] = @response_template.errors_as_sentence # this will probably never fail
|
|
end
|
|
|
|
redirect_back(fallback_location: admin_response_templates_path)
|
|
end
|
|
|
|
private
|
|
|
|
def permitted_params
|
|
params.require(:response_template).permit(:body_markdown, :user_id, :content, :title, :type_of, :content_type)
|
|
end
|
|
end
|
|
end
|