about summary refs log tree commit diff stats
path: root/app/controllers/admin/comments_controller.rb
blob: ccde3e6572784062c0113214add0ad31751f2a21 (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
class Admin::CommentsController < Admin::AdminController
  before_action :set_section

  def index
    @comments = Comment.where(status: :published).order(updated_at: :desc).paginate(page: params[:page], per_page: 20)
  end

  def pending
    @comments = Comment.where(status: :pending).order(updated_at: :desc).paginate(page: params[:page], per_page: 20)
  end

  def accept
    @comment = Comment.find(params[:id])
    @comment.status = :published
    @comment.save!

    flash.notice = "Comment successfully published."
    redirect_to pending_admin_comments_url
  end

  def reject
    @comment = Comment.find(params[:id])
    @comment.status = :rejected
    @comment.save!

    flash.notice = "Comment successfully rejected."
    redirect_to pending_admin_comments_url
  end

  def destroy
    if Comment.destroy(params[:id])
      flash.notice = "Comment successfully deleted."
    else
      flash.alert = "Could not delete comment."
    end

    redirect_to admin_comments_url
  end

  private

    def set_section
      @section = "comments"
    end
end