* feat: make the sidebar more dynamic * refactor: use the action in the same controller instead of the whole path * feat: remove hardcoded routes * feat: move routes into file * feat: use rails 6 draw for the admin routes * add a helper method * oops: fix super * feat: add the hacky helper methods :( ) * WIP: created different path helpers for the new routes and point the old helpers to the new ones if the FF is toggled * feat: update the module * chore: add new paths * feat: change link_to's use paths instead * feat: feedback_messages to scoped admin route * chore: update the feature flag urls helpers * feat: feedback_messages issue * chore: remove all the workarounds * chore: rubucop * fix: oops remove helper * chore: comment out the tests that touch the tabbed navbar which is affected by the rails application needing to be reloaded * feat: ensure that we chcek if the db table exists
76 lines
1.8 KiB
Ruby
76 lines
1.8 KiB
Ruby
module Admin
|
|
class DisplayAdsController < Admin::ApplicationController
|
|
layout "admin"
|
|
|
|
after_action :bust_ad_caches, only: %i[create update destroy]
|
|
|
|
def index
|
|
@display_ads = DisplayAd.order(id: :desc)
|
|
.joins(:organization)
|
|
.includes([:organization])
|
|
.page(params[:page]).per(50)
|
|
|
|
return if params[:search].blank?
|
|
|
|
@display_ads = @display_ads.where("organizations.name ILIKE :search", search: "%#{params[:search]}%")
|
|
end
|
|
|
|
def new
|
|
@display_ad = DisplayAd.new
|
|
end
|
|
|
|
def edit
|
|
@display_ad = DisplayAd.find(params[:id])
|
|
end
|
|
|
|
def create
|
|
@display_ad = DisplayAd.new(display_ad_params)
|
|
|
|
if @display_ad.save
|
|
flash[:success] = "Display Ad has been created!"
|
|
redirect_to admin_display_ads_path
|
|
else
|
|
flash[:danger] = @display_ad.errors_as_sentence
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def update
|
|
@display_ad = DisplayAd.find(params[:id])
|
|
|
|
if @display_ad.update(display_ad_params)
|
|
flash[:success] = "Display Ad has been updated!"
|
|
redirect_to admin_display_ads_path
|
|
else
|
|
flash[:danger] = @display_ad.errors_as_sentence
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@display_ad = DisplayAd.find(params[:id])
|
|
|
|
if @display_ad.destroy
|
|
flash[:success] = "Display Ad has been deleted!"
|
|
redirect_to admin_display_ads_path
|
|
else
|
|
flash[:danger] = "Something went wrong with deleting the Display Ad."
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def display_ad_params
|
|
params.permit(:organization_id, :body_markdown, :placement_area, :published, :approved)
|
|
end
|
|
|
|
def authorize_admin
|
|
authorize DisplayAd, :access?, policy_class: InternalPolicy
|
|
end
|
|
|
|
def bust_ad_caches
|
|
EdgeCache::BustSidebar.call
|
|
end
|
|
end
|
|
end
|