Files
grecia/app/controllers/admin/banners_controller.rb
iagirre 82cb8d4c52 Changes suggested in PR:
* Delete all things related to banner images and styles (in code)
* Add a new test to check that the banner is showing correctly
* Update the specs accordingly to match the changes

Update dev_seed to set a random background_color and a font_color for banners (and remove everything about image and style)
Add a rake task to migrate the banner style to backgroun_color and font_color (so that the banners have the same colors than before)
2018-07-12 10:17:24 -04:00

63 lines
1.4 KiB
Ruby

class Admin::BannersController < Admin::BaseController
has_filters %w{all with_active with_inactive}, only: :index
before_action :banner_sections, only: [:edit, :new, :create, :update]
respond_to :html, :js
load_and_authorize_resource
def index
@banners = Banner.send(@current_filter).page(params[:page])
end
def create
@banner = Banner.new(banner_params)
if @banner.save
redirect_to admin_banners_path
else
render :new
end
end
def update
if @banner.update(banner_params)
redirect_to admin_banners_path
else
render :edit
end
end
def destroy
@banner.destroy
redirect_to admin_banners_path
end
private
def banner_params
attributes = [:title, :description, :target_url,
:post_started_at, :post_ended_at,
:background_color, :font_color,
web_section_ids: []]
params.require(:banner).permit(*attributes)
end
def banner_styles
@banner_styles = Setting.all.banner_style.map do |banner_style|
[banner_style.value, banner_style.key.split('.')[1]]
end
end
def banner_imgs
@banner_imgs = Setting.all.banner_img.map do |banner_img|
[banner_img.value, banner_img.key.split('.')[1]]
end
end
def banner_sections
@banner_sections = WebSection.all
end
end