dawarich/app/controllers/notifications_controller.rb

31 lines
787 B
Ruby
Raw Normal View History

2024-07-04 16:20:12 -04:00
# frozen_string_literal: true
class NotificationsController < ApplicationController
before_action :authenticate_user!
before_action :set_notification, only: %i[show destroy]
def index
2024-07-04 17:00:07 -04:00
@notifications =
current_user.notifications.order(created_at: :desc).paginate(page: params[:page], per_page: 20)
2024-07-04 16:20:12 -04:00
end
def show; end
2024-07-04 17:00:07 -04:00
def mark_as_read
current_user.notifications.unread.update_all(read_at: Time.zone.now)
redirect_to notifications_url, notice: 'All notifications marked as read.', status: :see_other
end
2024-07-04 16:20:12 -04:00
def destroy
@notification.destroy!
redirect_to notifications_url, notice: 'Notification was successfully destroyed.', status: :see_other
end
private
def set_notification
@notification = Notification.find(params[:id])
end
end