We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
46 lines
1.1 KiB
Ruby
46 lines
1.1 KiB
Ruby
class NotificationsController < ApplicationController
|
|
before_action :authenticate_user!
|
|
skip_authorization_check
|
|
|
|
respond_to :html, :js
|
|
|
|
def index
|
|
@notifications = current_user.notifications.unread
|
|
end
|
|
|
|
def show
|
|
@notification = current_user.notifications.find(params[:id])
|
|
@notification.mark_as_read
|
|
redirect_to linkable_resource_path(@notification)
|
|
end
|
|
|
|
def read
|
|
@notifications = current_user.notifications.read
|
|
end
|
|
|
|
def mark_all_as_read
|
|
current_user.notifications.unread.each { |notification| notification.mark_as_read }
|
|
redirect_to notifications_path
|
|
end
|
|
|
|
def mark_as_read
|
|
@notification = current_user.notifications.find(params[:id])
|
|
@notification.mark_as_read
|
|
end
|
|
|
|
def mark_as_unread
|
|
@notification = current_user.notifications.find(params[:id])
|
|
@notification.mark_as_unread
|
|
end
|
|
|
|
private
|
|
|
|
def linkable_resource_path(notification)
|
|
if notification.linkable_resource.is_a?(AdminNotification)
|
|
notification.linkable_resource.link || notifications_path
|
|
else
|
|
polymorphic_hierarchy_path(notification.linkable_resource)
|
|
end
|
|
end
|
|
end
|