spam_logs_controller.rb 748 Bytes
Newer Older
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
class Admin::SpamLogsController < Admin::ApplicationController
  before_action :set_spam_log, only: [:destroy]

  def index
    @spam_logs = SpamLog.order(created_at: :desc).page(params[:page])
  end

  def destroy
    @spam_log.destroy
    message = 'Spam log was successfully destroyed.'

    if params[:remove_user]
      username = @spam_log.user.username
      @spam_log.user.destroy
      message = "User #{username} was successfully destroyed."
    end

    respond_to do |format|
      format.json { render json: '{}' }
      format.html { redirect_to admin_spam_logs_path, notice: message }
    end
  end

  private

  def set_spam_log
    @spam_log = SpamLog.find(params[:id])
  end

  def spam_log_params
    params[:spam_log]
  end
end