Files
growstuff/app/models/comment.rb
2018-12-30 15:22:29 +13:00

22 lines
606 B
Ruby

class Comment < ApplicationRecord
belongs_to :author, -> { with_deleted }, class_name: 'Member', inverse_of: :comments
belongs_to :post
scope :post_order, -> { reorder("created_at ASC") } # for display on post page
after_create do
recipient = post.author.id
sender = author.id
# don't send notifications to yourself
if recipient != sender
Notification.create(
recipient_id: recipient,
sender_id: sender,
subject: "#{author} commented on #{post.subject}",
body: body,
post_id: post.id
)
end
end
end