Class: NotificationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
NotificationsHelper
Defined in:
lib/generators/notifykit/templates/app/controllers/notifications_controller.rb

Instance Method Summary collapse

Instance Method Details

#cancelObject



62
63
64
65
66
67
68
69
# File 'lib/generators/notifykit/templates/app/controllers/notifications_controller.rb', line 62

def cancel
  notification.cancel

  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to root_url }
  end
end

#clickObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/notifykit/templates/app/controllers/notifications_controller.rb', line 24

def click
  notification.click

  # To prevent a bare redirect, validate that the redirect url
  # was generated when the email was sent
  target_url = params[:r]
  target_url = root_url if notification.email_urls.blank? || !notification.email_urls.split("\n").index(target_url)

  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to append_tracking_params(target_url) }
  end
end

#ignoreObject



53
54
55
56
57
58
59
60
# File 'lib/generators/notifykit/templates/app/controllers/notifications_controller.rb', line 53

def ignore
  notification.ignore

  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to root_url }
  end
end

#readObject



38
39
40
41
# File 'lib/generators/notifykit/templates/app/controllers/notifications_controller.rb', line 38

def read
  notification.read
  respond_with_no_content
end

#recentObject



11
12
13
14
15
# File 'lib/generators/notifykit/templates/app/controllers/notifications_controller.rb', line 11

def recent
  respond_to do |format|
    format.json { render json: recent_notifications.to_json }
  end
end

#unsubscribeObject



43
44
45
46
47
48
49
50
51
# File 'lib/generators/notifykit/templates/app/controllers/notifications_controller.rb', line 43

def unsubscribe
  notification.unsubscribe

  # TODO you may want to improve the unsubscribe logic here
  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to root_url }
  end
end

#viewObject



17
18
19
20
21
22
# File 'lib/generators/notifykit/templates/app/controllers/notifications_controller.rb', line 17

def view
  respond_to do |format|
    format.html { render text: notification.email_html }
    format.text { render text: notification.email_text }
  end
end