Class: Admin::NotificationsController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/notifications_controller.rb

Instance Method Summary collapse

Instance Method Details

#batchObject



37
38
39
40
41
42
43
# File 'app/controllers/admin/notifications_controller.rb', line 37

def batch
  return unless params[:read] == "all"

  current_user.notifications.mark_as_read!
  flash[:success] = "All notifications marked as read."
  redirect_to admin_notifications_url
end

#destroyObject



28
29
30
31
32
33
34
35
# File 'app/controllers/admin/notifications_controller.rb', line 28

def destroy
  @notification.file.purge
  @notification.destroy
  respond_to do |format|
    format.html { redirect_to admin_notifications_url, notice: "Notification was successfully destroyed." }
    format.json { head :no_content }
  end
end

#indexObject



8
9
10
# File 'app/controllers/admin/notifications_controller.rb', line 8

def index
  @pagy, @notifications = pagy(current_user.notifications.order(created_at: :desc), items: 20)
end

#updateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/admin/notifications_controller.rb', line 12

def update
  case params[:read]
  when "0"
    @notification.update(read_at: nil)
    @toast = "Notification marked unread."
  when "1"
    @notification.update(read_at: Time.zone.now)
    @toast = "Notification marked read."
  end

  respond_to do |format|
    format.html { redirect_to admin_notifications_url }
    format.js
  end
end