about summary refs log tree commit diff stats
path: root/app/controllers/admin/quotes_controller.rb
blob: 2c09627b69dcc3cbc3f47a949252e0b96b9265c0 (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
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 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
end