class Comment < ApplicationRecord belongs_to :commentable, polymorphic: true has_many :comments, as: :commentable belongs_to :user, optional: true acts_as_votable validates :body, presence: true def deleted? user.nil? end after_commit :create_notifications, on: :create private def create_notifications Notification.create do |notification| notification.notify_type = 'commentable' notification.actor = self.user notification.user = self.commentable.user notification.target = self notification.second_target = self.commentable end end end
NoMethodError (undefined method `user' for #<BlogPost:0x00007fc3cab54fd8>
Did you mean? super):
app/models/comment.rb:26:in `block in create_notifications'
app/models/comment.rb:23:in `create_notifications'
app/controllers/comments_controller.rb:17:in `create'
if self.commentable = self notification.user = commentable.user end