destroy notifications when marked as read

This commit is contained in:
rgarcia
2016-01-07 12:02:01 +01:00
parent b5e9113718
commit e2f419e625
12 changed files with 120 additions and 84 deletions

View File

@@ -1,9 +1,26 @@
class NotificationsController < ApplicationController
before_action :authenticate_user!
load_and_authorize_resource class: "User"
after_action :mark_as_read, only: :show
skip_authorization_check
def index
@notifications = current_user.notifications.recent.for_render
@notifications = current_user.notifications.unread.recent.for_render
end
def show
@notification = current_user.notifications.find(params[:id])
redirect_to url_for(@notification.notifiable.commentable)
end
def mark_all_as_read
current_user.notifications.each { |notification| notification.mark_as_read }
redirect_to notifications_path
end
private
def mark_as_read
@notification.mark_as_read
end
end