68 lines
1.5 KiB
Ruby
68 lines
1.5 KiB
Ruby
class Admin::AdImagesController < Admin::AdBannersController
|
|
def initialize
|
|
super
|
|
@app_title = "ad_banner"
|
|
end
|
|
|
|
def index
|
|
@ad_images = AdImage.order_by(sort).page(params[:page]).per(10)
|
|
@table_fields = ["preview","ad_banner.banner","title","start_date","end_date", "link"]
|
|
end
|
|
|
|
def edit
|
|
@ad_image = AdImage.find(params[:id])
|
|
if can_edit_or_delete?(@ad_image)
|
|
@ad_banner = @ad_image.banner
|
|
else
|
|
render_401
|
|
end
|
|
end
|
|
|
|
def update
|
|
@ad_image = AdImage.find(params[:id])
|
|
if @ad_image.update_attributes(ad_image_params)
|
|
redirect_to params['referer_url']
|
|
else
|
|
@ad_banners = Banner.all
|
|
@tags = @module_app.tags || []
|
|
render action: :edit
|
|
end
|
|
end
|
|
|
|
def new
|
|
@ad_image = AdImage.new
|
|
@ad_banner = Banner.find(params[:banner])
|
|
@tags = @module_app.tags || []
|
|
|
|
@ad_image.postdate = Date.today
|
|
end
|
|
|
|
def create
|
|
@ad_image = AdImage.new(ad_image_params)
|
|
if @ad_image.save
|
|
redirect_to params['referer_url']
|
|
else
|
|
@ad_banners = Banner.all
|
|
@tags = @module_app.tags || []
|
|
@ad_image = AdImage.new(ad_image_params)
|
|
render action: :new
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@ad_image = AdImage.find params[:id]
|
|
if @ad_image.destroy
|
|
redirect_to admin_ad_banners_url
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def ad_image_params
|
|
params.require(:ad_image).permit!
|
|
end
|
|
|
|
def setup_vars
|
|
@module_app = ModuleApp.where(:key => "ad_banner").first
|
|
end
|
|
end |