forgeplus/app/controllers/admins/page_themes_controller.rb

62 lines
1.6 KiB
Ruby

class Admins::PageThemesController < Admins::Topic::BaseController
before_action :finder_page_theme, only: [:edit, :update, :destroy]
def index
params[:sort_by] = params[:sort_by].presence || 'created_at'
params[:sort_direction] = params[:sort_direction].presence || 'desc'
page_themes = Admins::PageThemesQuery.call(params)
@page_themes = paginate page_themes
end
def show
render 'edit'
end
def edit
end
def create
@page_theme = PageTheme.new update_params
if @page_theme.save
save_image_file(params[:image_url], @page_theme)
redirect_to admins_page_themes_path
flash[:success] = "新增主题成功"
else
redirect_to admins_page_themes_path
flash[:danger] = "新增主题失败: #{@page_theme.errors.messages.values.flatten.join(',')}"
end
end
def destroy
if @page_theme.destroy
redirect_to admins_page_themes_path
flash[:success] = "删除主题成功"
else
redirect_to admins_page_themes_path
flash[:danger] = "删除主题失败"
end
end
def new
@page_theme = PageTheme.new
end
def update
@page_theme.update(update_params)
flash[:success] = '保存成功'
render 'edit'
end
private
def finder_page_theme
@page_theme = PageTheme.find(params[:id])
end
def update_params
params.require(:page_theme).permit(:language_frame, :name, :cate, :image_url, :clone_url)
end
end