Class: WcoEmail::UnsubscribesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/wco_email/unsubscribes_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
# File 'app/controllers/wco_email/unsubscribes_controller.rb', line 5

def create
  authorize! :open_permission, Wco
  @lead = Wco::Lead.find params[:lead_id]

  if( !params[:token] ||
      @lead.unsubscribe_token != params[:token] )
    render code: 400, message: "We're sorry, but something went wrong. Please try again later."
    return
  end

  @unsubscribe = WcoEmail::Unsubscribe.find_or_create_by({
    lead_id:     params[:lead_id],
    template_id: params[:template_id],
    campaign_id: params[:campaign_id],
  })
  flag = @unsubscribe.update_attributes({
    unsubscribed_at: Time.now,
  })
  if flag
    flash_notice "You have been unsubscribed."
  else
    flash_alert "We're sorry, but something went wrong. Please try again later."
  end

  render layout: false
end

#indexObject



32
33
34
35
36
37
# File 'app/controllers/wco_email/unsubscribes_controller.rb', line 32

def index
  authorize! :index, WcoEmail::Unsubscribe
  @unsubscribes = WcoEmail::Unsubscribe.all

  render '_table'
end