2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2019-02-01 19:40:24 +00:00
|
|
|
class Comment < ApplicationRecord
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-06-21 22:12:54 +00:00
|
|
|
#TODO
|
|
|
|
# attr_accessible \
|
|
|
|
# :host_id, :host_type, #parent: Event, Campaign, nil
|
|
|
|
# :profile_id,
|
|
|
|
# :body
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
validates :profile, :presence => true
|
|
|
|
validates :body, :presence => true, :length => {:maximum => 200}
|
|
|
|
|
|
|
|
has_one :activity, :as => :attachment, :dependent => :destroy
|
|
|
|
belongs_to :host, :polymorphic => true
|
|
|
|
belongs_to :donation
|
|
|
|
belongs_to :profile
|
|
|
|
|
|
|
|
before_validation(:on => :create) do
|
|
|
|
remove_newlines
|
|
|
|
end
|
|
|
|
|
|
|
|
after_create do
|
|
|
|
self.create_activity({
|
|
|
|
:desc => 'commented',
|
|
|
|
:profile_id => self.profile_id,
|
|
|
|
:host_id => self.host_id,
|
|
|
|
:host_type => self.host_type,
|
|
|
|
:body => self.body
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_newlines
|
|
|
|
self.body = self.body && self.body.gsub(/\n/,'')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|