avoids queries when creating a notification

This commit is contained in:
Juanjo Bazán
2016-01-08 12:35:23 +01:00
committed by Juanjo Bazán
parent de51bb0f79
commit ab74bd58fa

View File

@@ -65,11 +65,11 @@ class CommentsController < ApplicationController
def add_notification(comment)
if comment.reply?
author = comment.parent.author
notifiable = comment.parent
else
author = comment.commentable.author
notifiable = comment.commentable
end
author.notifications.create!(notifiable: comment) unless comment.made_by? author
Notification.create!(user_id: notifiable.author_id, notifiable: comment) unless comment.author_id == notifiable.author_id
end
end