about summary refs log tree commit diff stats
path: root/app/controllers/admin/quotes_controller.rb
blob: 362346336e15dc275e4ddedf6a2c6c9e870fc743 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Admin::QuotesController < Admin::AdminController
  before_action :set_section

  def index
    @quotes = Quote.published.order(id: :desc).paginate(page: params[:page], per_page: 20)
  end

  def pending
    @quotes = Quote.pending.order(id: :desc).paginate(page: params[:page], per_page: 20)
  end

  def edit
    @quote = Quote.find(params[:id])
  end

  def update
    @quote = Quote.find(params[:id])

    if @quote.update(quote_params)
      flash[:notice] = "Quote was successfully updated."
    else
      flash[:error] = "Error updating quote."
    end

    render :edit
  end

  def accept
    @quote = Quote.find(params[:id])
    @quote.state = :published
    @quote.save!

    flash.notice = "Quote successfully accepted."
    redirect_to pending_admin_quotes_url
  end

  def destroy
    @quote = Quote.find(params[:id])
    @quote.destroy!

    flash.notice = "Quote successfully rejected."
    redirect_to pending_admin_quotes_url
  end

  private

    def set_section
      @section = "quotes"
    end

    def quote_params
      params.require(:quote).permit(:content, :state, :notes, :submitter, :tag_list, :audio)
    end
end