diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 5b500fc..c44b721 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -7,40 +7,8 @@ def index end def update - @notification = Notification.find(params[:id]) - @notification.clicked! - redirect_to_notification - end - - private - - def redirect_to_notification - return redirect_to_invitation if @notification.notifiable.is_a? Invitation - return redirect_to_comment if @notification.notifiable.is_a? Comment - return redirect_to_connection if @notification.notifiable.is_a? Connection - return redirect_to_post if @notification.notifiable.is_a? Post - - redirect_to_like if @notification.notifiable.is_a? Like - end - - def redirect_to_invitation - redirect_to invitation_path(@notification.notifiable) - end - - def redirect_to_comment - redirect_to post_path(@notification.notifiable.post) - end - - def redirect_to_connection - redirect_to profile_path(@notification.notifiable.follower) - end - - def redirect_to_post - redirect_to post_path(@notification.notifiable) - end - - def redirect_to_like - likeable = @notification.notifiable.likeable - redirect_to post_path(likeable.is_a?(Comment) ? likeable.post : likeable) + notification = Notification.find(params[:id]) + notification.clicked! + redirect_to NotificationDecorator.new(notification).redirect_path end end diff --git a/app/models/notification_decorator.rb b/app/models/notification_decorator.rb new file mode 100644 index 0000000..ad86f0a --- /dev/null +++ b/app/models/notification_decorator.rb @@ -0,0 +1,14 @@ +class NotificationDecorator < SimpleDelegator + def redirect_path + case notifiable + when Comment + notifiable.post + when Connection + notifiable.follower + when Post, Invitation + notifiable + else + notifiable.likeable.is_a?(Comment) ? notifiable.likeable.post : notifiable.likeable + end + end +end