Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

comment.rb 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class Comment < ActiveRecord::Base
  18. include Redmine::SafeAttributes
  19. belongs_to :commented, :polymorphic => true, :counter_cache => true
  20. belongs_to :author, :class_name => 'User'
  21. validates_presence_of :commented, :author, :content
  22. after_create_commit :send_notification
  23. safe_attributes 'comments'
  24. def comments=(arg)
  25. self.content = arg
  26. end
  27. def comments
  28. content
  29. end
  30. private
  31. def send_notification
  32. event = "#{commented.class.name.underscore}_comment_added"
  33. if Setting.notified_events.include?(event)
  34. Mailer.public_send("deliver_#{event}", self)
  35. end
  36. end
  37. end