Implements admin interface for Comments incl. filters
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user