BigW Consortium Gitlab

broadcast_messages_controller.rb 959 Bytes
Newer Older
1
class Admin::BroadcastMessagesController < Admin::ApplicationController
2
  before_action :broadcast_messages
3 4 5 6 7 8

  def index
    @broadcast_message = BroadcastMessage.new
  end

  def create
9
    @broadcast_message = BroadcastMessage.new(broadcast_message_params)
10 11 12 13 14 15 16 17

    if @broadcast_message.save
      redirect_to admin_broadcast_messages_path, notice: 'Broadcast Message was successfully created.'
    else
      render :index
    end
  end

18 19 20 21
  def destroy
    BroadcastMessage.find(params[:id]).destroy

    respond_to do |format|
22
      format.html { redirect_back_or_default(default: { action: 'index' }) }
23 24 25 26
      format.js { render nothing: true }
    end
  end

27 28 29 30 31
  protected

  def broadcast_messages
    @broadcast_messages ||= BroadcastMessage.order("starts_at DESC").page(params[:page])
  end
32 33 34 35 36 37 38

  def broadcast_message_params
    params.require(:broadcast_message).permit(
      :alert_type, :color, :ends_at, :font,
      :message, :starts_at
    )
  end
39
end