add: message template management

This commit is contained in:
2021-09-18 18:41:03 +08:00
parent 74a4b499a9
commit d957e0544f
9 changed files with 145 additions and 2 deletions

View File

@@ -0,0 +1,34 @@
class Admins::MessageTemplatesController < Admins::BaseController
before_action :get_template, only: [:edit,:update, :destroy]
def index
message_templates = MessageTemplate.group(:type).count.keys
@message_templates = kaminari_array_paginate(message_templates)
end
def edit
end
def update
if @message_template.update_attributes(message_template_params)
redirect_to admins_message_templates_path
flash[:success] = '消息模版更新成功'
else
redirect_to admins_message_templates_path
flash[:danger] = @message_template.errors.full_messages.join(",")
end
end
private
def message_template_params
params.require(:message_template).permit!
end
def get_template
@message_template = MessageTemplate.find_by(id: params[:id])
unless @message_template.present?
redirect_to admins_message_templates_path
flash[:danger] = "消息模版不存在"
end
end
end