Class: Trackguard::Admin::VisitorsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/trackguard/admin/visitors_controller.rb

Instance Method Summary collapse

Instance Method Details

#flagObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/trackguard/admin/visitors_controller.rb', line 14

def flag
  if @visitor.update(
    flagged_at: Time.current,
    flag_reason: params[:flag_reason].presence,
    flagged_by: params[:flagged_by].presence || Visitor::FLAGGED_BY.first
  )
    respond_to do |format|
      format.html { redirect_back_or_to dashboard_path }
      format.json { render json: { status: "ok", ip: @visitor.ip, flagged_at: @visitor.flagged_at } }
    end
  else
    respond_to do |format|
      format.html { redirect_back_or_to dashboard_path, alert: @visitor.errors.full_messages.join(", ") }
      format.json { render json: { errors: @visitor.errors.full_messages }, status: :unprocessable_entity }
    end
  end
end

#unflagObject



32
33
34
35
36
37
38
# File 'app/controllers/trackguard/admin/visitors_controller.rb', line 32

def unflag
  @visitor.update!(flagged_at: nil, flag_reason: nil, flagged_by: nil)
  respond_to do |format|
    format.html { redirect_back_or_to dashboard_path }
    format.json { render json: { status: "ok", ip: @visitor.ip } }
  end
end