Implements admin interface for Comments incl. filters

This commit is contained in:
kikito
2015-08-28 10:56:43 +02:00
parent 76c2f2f021
commit a5e48693fe
4 changed files with 111 additions and 39 deletions

View File

@@ -1,13 +1,35 @@
class Admin::CommentsController < Admin::BaseController
before_filter :set_valid_filters, only: :index
before_filter :parse_filter, only: :index
before_filter :load_comment, only: [:confirm_hide, :restore]
def index
@comments = Comment.only_hidden.page(params[:page])
@comments = Comment.only_hidden.send(@filter).page(params[:page])
end
def confirm_hide
@comment.confirm_hide
redirect_to request.query_parameters.merge(action: :index)
end
def restore
@comment = Comment.with_hidden.find(params[:id])
@comment.restore
redirect_to admin_comments_path, notice: t('admin.comments.restore.success')
redirect_to request.query_parameters.merge(action: :index)
end
end
private
def load_comment
@comment = Comment.with_hidden.find(params[:id])
end
def set_valid_filters
@valid_filters = %w{all with_confirmed_hide}
end
def parse_filter
@filter = params[:filter]
@filter = 'all' unless @valid_filters.include?(@filter)
end
end