forked from Trustie/forgeplus
60 lines
1.6 KiB
Ruby
60 lines
1.6 KiB
Ruby
class Admins::Topic::AppletBannersController < Admins::Topic::BaseController
|
|
before_action :find_banner, only: [:edit, :update, :destroy]
|
|
|
|
def index
|
|
@banners = ::Topic::AppletBanner
|
|
@banners = @banners.where("title like ?", "%#{params[:search]}%") if params[:search].present?
|
|
@banners = @banners.where(location: params[:location]) if params[:location].present?
|
|
@banners = paginate(@banners)
|
|
end
|
|
|
|
def new
|
|
@banner = ::Topic::AppletBanner.new
|
|
end
|
|
|
|
def create
|
|
@banner = ::Topic::AppletBanner.new(banner_params)
|
|
if @banner.save
|
|
save_image_file(params[:image], @banner)
|
|
redirect_to admins_topic_applet_banners_path
|
|
flash[:success] = "新增banner成功"
|
|
else
|
|
redirect_to admins_topic_applet_banners_path
|
|
flash[:danger] = "新增banner失败"
|
|
end
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
@banner.attributes = banner_params
|
|
if @banner.save
|
|
save_image_file(params[:image], @banner)
|
|
redirect_to admins_topic_applet_banners_path
|
|
flash[:success] = "更新banner成功"
|
|
else
|
|
redirect_to admins_topic_applet_banners_path
|
|
flash[:danger] = "更新banner失败"
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
if @banner.destroy
|
|
redirect_to admins_topic_applet_banners_path
|
|
flash[:success] = "删除banner成功"
|
|
else
|
|
redirect_to admins_topic_applet_banners_path
|
|
flash[:danger] = "删除banner失败"
|
|
end
|
|
end
|
|
|
|
private
|
|
def find_banner
|
|
@banner = ::Topic::AppletBanner.find_by_id(params[:id])
|
|
end
|
|
|
|
def banner_params
|
|
params.require(:topic_applet_banner).permit(:title, :order_index, :url, :location)
|
|
end
|
|
end |