Class: Gold::Admin::ReferralsController

Inherits:
AdminController show all
Defined in:
app/controllers/gold/admin/referrals_controller.rb

Overview

Controller for referrals

Instance Method Summary collapse

Instance Method Details

#add_billingObject



41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/gold/admin/referrals_controller.rb', line 41

def add_billing
  referral = Referral.find_by(id: params[:referral_id])
  billing = Billing.find(params[:billing_id])

  billing.update(referral: referral)

  flash[:success] = "Updated referral"

  redirect_back(fallback_location: "/admin")
end

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/gold/admin/referrals_controller.rb', line 5

def create
  referral = Referral.new(referral_params)

  if referral.save
    flash[:success] = "Created new referrer"
  else
    message = referral.errors.full_messages.join(", ")
    flash[:danger] = "Failed to create, #{message}"
  end

  redirect_to "#{request.path}/#{referral.id}"
end

#deleteObject



31
32
33
34
35
36
37
38
39
# File 'app/controllers/gold/admin/referrals_controller.rb', line 31

def delete
  referral = Referral.find(params[:id])

  referral.destroy!

  flash[:success] = "Poof! Code #{referral.code} no longer exists"

  redirect_to gold_admin_engine.referrals_path
end

#updateObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/gold/admin/referrals_controller.rb', line 18

def update
  referral = Referral.find(params[:id])

  if referral.update(referral_params)
    flash[:success] = "Update referrer"
  else
    message = referral.errors.full_messages.join(", ")
    flash[:danger] = "Failed to update, #{message}"
  end

  redirect_back(fallback_location: "/admin")
end