forgeplus/app/controllers/admins/message_templates_controlle...

62 lines
1.8 KiB
Ruby
Raw Permalink Normal View History

2021-09-18 18:41:03 +08:00
class Admins::MessageTemplatesController < Admins::BaseController
2021-09-22 14:25:56 +08:00
before_action :get_template, only: [:edit, :update, :destroy]
2021-09-18 18:41:03 +08:00
def index
2022-06-01 10:00:57 +08:00
message_templates = MessageTemplate.ransack(sys_notice_or_email_or_email_title_cont: params[:search]).result
@message_templates = kaminari_paginate(message_templates)
end
def new
2022-08-10 17:43:27 +08:00
@message_template = MessageTemplate.new
2022-06-01 10:00:57 +08:00
end
2022-08-10 17:20:29 +08:00
def create
2022-08-10 16:54:00 +08:00
@message_template = MessageTemplate::CustomTip.new(message_template_params)
2022-08-10 17:25:55 +08:00
@message_template.type = "MessageTemplate::CustomTip"
2022-06-01 10:00:57 +08:00
if @message_template.save!
redirect_to admins_message_templates_path
flash[:success] = "创建消息模板成功"
else
render :new
flash[:danger] = "创建消息模板失败"
end
2021-09-18 18:41:03 +08:00
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
2021-09-22 09:53:43 +08:00
def init_data
if MessageTemplate.build_init_data
redirect_to admins_message_templates_path
flash[:success] = '消息模版初始化成功'
else
redirect_to admins_message_templates_path
flash[:danger] = '消息模版初始化失败'
end
end
2021-09-18 18:41:03 +08:00
private
2021-09-22 14:25:56 +08:00
def message_template_params
2022-08-10 17:43:27 +08:00
# type = @message_template.present? ? @message_template.type : "MessageTemplate::CustomTip"
# params.require(type.split("::").join("_").underscore.to_sym).permit!
params.require(:message_template).permit!
2021-09-18 18:41:03 +08:00
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