docbrown/app/controllers/internal/broadcasts_controller.rb
Julianna Tetreault 426d3191e8
Add a Broadcast Show View (#8769) [deploy]
* Add #show to the Broadcasts::Controller and to routes.rb
  - Adds a show method to the Broadcasts Controller
  - Adds a show route to routes.rb

* Add a show view for Broadcasts
  - Adds show.html.erb to /internal/broadcasts
  - Repurposes code from index.html.erb for show view
  - Repurposes code from edit.html.erb for show view

* Rewrite /internal/broadcasts index to use a table
  - Formats /internal/broadcasts with a table
  - Removes on-hover functionality from show.html.erb

* Refactor Broadcast resources in routes.rb

* Redirect to #show on create and update for Broadcasts

* Add the Destroy Broadcast button to the Broadcast show view

* Remove style preventing Broadcast preview

* Add Broadcast styling back and add display: block to stylesheet

* Add display: flex to .broadcast-wrapper in layout.scss

* Remove superfluous slashes from opening tags
2020-06-18 15:51:45 -06:00

69 lines
1.6 KiB
Ruby

class Internal::BroadcastsController < Internal::ApplicationController
layout "internal"
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 internal_broadcast_path(@broadcast)
else
flash[:danger] = @broadcast.errors.full_messages.to_sentence
render new_internal_broadcast_path
end
end
def update
@broadcast = Broadcast.find(params[:id])
if @broadcast.update(broadcast_params)
flash[:success] = "Broadcast has been updated!"
redirect_to internal_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 internal_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