Files
growstuff/app/models/comment.rb
2017-01-14 17:23:39 +13:00

23 lines
587 B
Ruby

class Comment < ActiveRecord::Base
belongs_to :author, class_name: 'Member'
belongs_to :post
default_scope { order("created_at DESC") }
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