Class: Nuntius::SubscribersController

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

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
# File 'app/controllers/nuntius/subscribers_controller.rb', line 16

def create
  @subscriber = Nuntius::Subscriber.new(subscriber_params)
  if @subscriber.save
    Signum.success(request.session.id, text: "You have been subscribed.")
    redirect_to nuntius.edit_subscriber_path(@subscriber), status: :see_other
  else
    render :edit, status: :unprocessable_entity
  end
end

#editObject



26
27
28
29
# File 'app/controllers/nuntius/subscribers_controller.rb', line 26

def edit
  @subscriber = Nuntius::Subscriber.find(params[:id])
  @list = @subscriber.list
end

#newObject



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

def new
  @subscriber = Nuntius::Subscriber.new(list: Nuntius::List.find(params[:list_id]))
  render :edit
end

#showObject



42
43
44
45
46
47
48
49
50
# File 'app/controllers/nuntius/subscribers_controller.rb', line 42

def show
  @subscriber = Nuntius::Subscriber.find_by(id: params[:id])
  if @subscriber
    @list = @subscriber.list
  else
    flash[:notice] = "Subscription not found."
    redirect_to root_path, status: :see_other
  end
end

#subscribeObject



52
53
54
55
56
57
58
# File 'app/controllers/nuntius/subscribers_controller.rb', line 52

def subscribe
  @subscriber = Nuntius::Subscriber.find(params[:id])
  @subscriber.update(unsubscribed_at: nil)
  Signum.success(request.session.id, text: "Subscription has been restored.")

  redirect_to nuntius.subscriber_path(@subscriber), status: :see_other
end

#unsubscribeObject



60
61
62
63
64
65
# File 'app/controllers/nuntius/subscribers_controller.rb', line 60

def unsubscribe
  @subscriber = Nuntius::Subscriber.find(params[:id])
  @subscriber.touch(:unsubscribed_at)
  Signum.success(request.session.id, text: "Subscription has been removed.")
  redirect_to nuntius.subscriber_path(@subscriber), status: :see_other
end

#updateObject



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/nuntius/subscribers_controller.rb', line 31

def update
  @subscriber = Nuntius::Subscriber.find(params[:id])
  @list = @subscriber.list
  if @subscriber.update(subscriber_params)
    Signum.success(request.session.id, text: "Subscription has been updated.")
    redirect_to nuntius.edit_subscriber_path(@subscriber), status: :see_other
  else
    render :edit, status: :unprocessable_entity
  end
end