more before_destroy and after_create
This commit is contained in:
parent
bb3e431393
commit
40f54fd19a
|
@ -35,10 +35,7 @@ class Ajax::CommentController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
comment.user.decrement! :commented_count
|
||||
comment.answer.decrement! :comment_count
|
||||
Notification.denotify comment.answer.user, comment
|
||||
@count = comment.answer.comment_count
|
||||
@count = comment.answer.comment_count - 1
|
||||
comment.destroy
|
||||
|
||||
@status = :okay
|
||||
|
|
|
@ -6,6 +6,18 @@ class Comment < ActiveRecord::Base
|
|||
|
||||
validates :content, length: { maximum: 160 }
|
||||
|
||||
after_create do
|
||||
Notification.notify answer.user, self unless answer.user == self.user
|
||||
user.increment! :commented_count
|
||||
answer.increment! :comment_count
|
||||
end
|
||||
|
||||
before_destroy do
|
||||
Notification.denotify answer.user, self unless answer.user == self.user
|
||||
user.decrement! :commented_count
|
||||
answer.decrement! :comment_count
|
||||
end
|
||||
|
||||
def notification_type(*_args)
|
||||
Notifications::Commented
|
||||
end
|
||||
|
|
|
@ -5,10 +5,13 @@ class Question < ActiveRecord::Base
|
|||
|
||||
validates :content, length: { maximum: 255 }
|
||||
|
||||
before_destroy do
|
||||
user.decrement! :asked_count unless self.author_is_anonymous
|
||||
end
|
||||
|
||||
def can_be_removed?
|
||||
return false if self.answers.count > 0
|
||||
return false if Inbox.where(question: self).count > 1
|
||||
self.user.decrement! :asked_count unless self.author_is_anonymous
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -107,10 +107,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def comment(answer, content)
|
||||
comment = Comment.create!(user: self, answer: answer, content: content)
|
||||
Notification.notify answer.user, comment unless answer.user == self
|
||||
increment! :commented_count
|
||||
answer.increment! :comment_count
|
||||
Comment.create!(user: self, answer: answer, content: content)
|
||||
end
|
||||
|
||||
# @return [Boolean] is the user a moderator?
|
||||
|
|
Loading…
Reference in New Issue