broadcast_messages_controller.rb 1.28 KB
Newer Older
1
class Admin::BroadcastMessagesController < Admin::ApplicationController
2
  before_action :finder, only: [:edit, :update, :destroy]
3
4

  def index
5
    @broadcast_messages = BroadcastMessage.reorder("ends_at DESC").page(params[:page])
6
7
8
9
    @broadcast_message  = BroadcastMessage.new
  end

  def edit
10
11
12
  end

  def create
13
    @broadcast_message = BroadcastMessage.new(broadcast_message_params)
14
15
16
17
18
19
20
21

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

22
23
24
25
26
27
28
29
  def update
    if @broadcast_message.update(broadcast_message_params)
      redirect_to admin_broadcast_messages_path, notice: 'Broadcast Message was successfully updated.'
    else
      render :edit
    end
  end

30
  def destroy
31
    @broadcast_message.destroy
32
33

    respond_to do |format|
34
      format.html { redirect_back_or_default(default: { action: 'index' }) }
35
      format.js { head :ok }
36
37
38
    end
  end

39
40
41
42
  def preview
    @message = broadcast_message_params[:message]
  end

43
44
  protected

45
46
  def finder
    @broadcast_message = BroadcastMessage.find(params[:id])
47
  end
48
49

  def broadcast_message_params
50
51
52
53
54
55
56
    params.require(:broadcast_message).permit(%i(
      color
      ends_at
      font
      message
      starts_at
    ))
57
  end
58
end