Files
growstuff/app/models/comment.rb
Skud e17dcf8671 Reordered comments: they are now DESC by default
Added scope "post_order" to order them ASC for display on post page.
Also tweaked post/comment views a bit.
2013-05-24 14:36:58 +10:00

25 lines
671 B
Ruby

class Comment < ActiveRecord::Base
attr_accessible :author_id, :body, :post_id
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 = self.post.author.id
sender = self.author.id
# don't send notifications to yourself
if recipient != sender
Notification.create(
:recipient_id => recipient,
:sender_id => sender,
:subject => "#{self.author} commented on #{self.post.subject}",
:body => self.body,
:post_id => self.post.id
)
end
end
end