docbrown/app/controllers/admin/broadcasts_controller.rb
Josh Puetz 1c566e0ec4
[deploy] Move /internal to `/admin (#9639)
* First draft - all the big changes

* Changing some more references to 'internal'

* Relocate internal request tests to admin

* Relocate internal system tests to admin

* Fix trailing space

* Test fix

* Move queries from internal to admin

* Docs updates

* Rename internal stimuls controllers to admin (plus docs)

* Rename admin layout

* Fix routing after rebase

* Fixes for latest added admin interfaces

* Serviceworker ignore paths
2020-08-07 10:36:26 -04:00

71 lines
1.7 KiB
Ruby

module Admin
class BroadcastsController < Admin::ApplicationController
layout "admin"
def index
@broadcasts = if params[:type_of]
Broadcast.where(type_of: params[:type_of].capitalize)
else
Broadcast.all
end.order(title: :asc)
end
def show
@broadcast = Broadcast.find(params[:id])
end
def new
@broadcast = Broadcast.new
end
def edit
@broadcast = Broadcast.find(params[:id])
end
def create
@broadcast = Broadcast.new(broadcast_params)
if @broadcast.save
flash[:success] = "Broadcast has been created!"
redirect_to admin_broadcast_path(@broadcast)
else
flash[:danger] = @broadcast.errors.full_messages.to_sentence
render new_admin_broadcast_path
end
end
def update
@broadcast = Broadcast.find(params[:id])
if @broadcast.update(broadcast_params)
flash[:success] = "Broadcast has been updated!"
redirect_to admin_broadcast_path(@broadcast)
else
flash[:danger] = @broadcast.errors.full_messages.to_sentence
render :edit
end
end
def destroy
@broadcast = Broadcast.find(params[:id])
if @broadcast.destroy
flash[:success] = "Broadcast has been deleted!"
redirect_to admin_broadcasts_path
else
flash[:danger] = "Something went wrong with deleting the broadcast."
render :edit
end
end
private
def broadcast_params
params.permit(:title, :processed_html, :type_of, :banner_style, :active)
end
def authorize_admin
authorize Broadcast, :access?, policy_class: InternalPolicy
end
end
end