Class: Chaskiq::SubscribersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/chaskiq/subscribers_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authentication_method, #get_referrer

Instance Method Details

#createObject



35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/chaskiq/subscribers_controller.rb', line 35

def create
  @subscriber = @campaign.list.create_subscriber(resource_params)
  if @subscriber.errors.blank?
    @subscription = @campaign.subscriptions.find_by(subscriber: @subscriber)
    @subscription.subscribe! unless @subscription.subscribed?
    flash[:notice] = "you did it!"
    redirect_to campaign_path(@campaign)
  else
    render "new"
  end
end

#deleteObject



47
48
49
# File 'app/controllers/chaskiq/subscribers_controller.rb', line 47

def delete
  find_subscriber
end

#destroyObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/chaskiq/subscribers_controller.rb', line 51

def destroy
  find_subscriber
  begin
    if @subscription.unsubscribe!
      flash[:notice] = "Thanks, you will not receive more emails from this newsletter!"
      redirect_to campaign_path(@campaign)
    end
  rescue
    flash[:notice] = "Thanks, you will not receive more emails from this newsletter!"
    redirect_to campaign_path(@campaign)
  end
end

#editObject



20
21
22
# File 'app/controllers/chaskiq/subscribers_controller.rb', line 20

def edit
  find_subscriber
end

#newObject



16
17
18
# File 'app/controllers/chaskiq/subscribers_controller.rb', line 16

def new
  @subscriber = @campaign.subscribers.new
end

#showObject



10
11
12
13
14
# File 'app/controllers/chaskiq/subscribers_controller.rb', line 10

def show
  #TODO, we should obfustate code
  find_subscriber
  render "edit"
end

#updateObject



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/chaskiq/subscribers_controller.rb', line 24

def update
  find_subscriber
  if @subscriber.update_attributes(resource_params) && @subscriber.errors.blank?
    flash[:notice] = "you did it!"
    @subscription.subscribe! unless @subscription.subscribed?
    redirect_to campaign_path(@campaign)
  else
    render "edit"
  end
end