Class: Admin::NotificationsController

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

Instance Method Summary collapse

Instance Method Details

#batchvoid

This method returns an undefined value.

POST /admin/notifications/batch

Marks all notifications as read.



61
62
63
64
65
66
67
# File 'app/controllers/admin/notifications_controller.rb', line 61

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

#destroyvoid

This method returns an undefined value.

DELETE /admin/notifications/:id

Destroys a notification and purges its associated file.



47
48
49
50
51
52
53
54
# File 'app/controllers/admin/notifications_controller.rb', line 47

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

#indexvoid

This method returns an undefined value.

GET /admin/notifications

Lists all notifications for the current user, paginated.



16
17
18
# File 'app/controllers/admin/notifications_controller.rb', line 16

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

#updatevoid

This method returns an undefined value.

PATCH/PUT /admin/notifications/:id

Updates the read status of a notification.

Parameters:

  • read (String)

    The read status, “0” for unread, “1” for read.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/admin/notifications_controller.rb', line 26

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