Class: Comment

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Gravtastic
Defined in:
app/models/comment.rb

Instance Method Summary collapse

Instance Method Details

#akismet_attributesObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/comment.rb', line 56

def akismet_attributes
  {
    :key                  => '4a8bfe691b69',
    :blog                 => "http://#{DOMAIN}",
    :user_ip              => user_ip,
    :user_agent           => user_agent,
    :comment_author       => author,
    :comment_author_email => email,
    :comment_author_url   => author_url,
    :comment_content      => body
  }
end

#anonymous?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/comment.rb', line 27

def anonymous?
  !user_id?
end

#authorObject



35
36
37
# File 'app/models/comment.rb', line 35

def author
  user_id.blank? ? author_name : user.to_s
end

#author_urlObject



39
40
41
# File 'app/models/comment.rb', line 39

def author_url
  anonymous? ? read_attribute(:author_url) : user.url
end

#check_for_spamObject



51
52
53
54
# File 'app/models/comment.rb', line 51

def check_for_spam
  self.approved = !Akismetor.spam?(akismet_attributes)
  true # return true so it doesn't stop save
end

#emailObject



31
32
33
# File 'app/models/comment.rb', line 31

def email
  user_id.blank? ? author_email : user.email
end

#email_post_authorObject



23
24
25
# File 'app/models/comment.rb', line 23

def 
  Notifier.deliver_new_comment_alert(self) unless user_id == post.user_id
end

#mark_as_ham!Object



74
75
76
77
# File 'app/models/comment.rb', line 74

def mark_as_ham!
  update_attribute(:approved, true)
  Akismetor.submit_ham(akismet_attributes)
end

#mark_as_spam!Object



69
70
71
72
# File 'app/models/comment.rb', line 69

def mark_as_spam!
  update_attribute(:approved, false)
  Akismetor.submit_spam(akismet_attributes)
end

#request=(request) ⇒ Object



45
46
47
48
49
# File 'app/models/comment.rb', line 45

def request=(request)
  self.user_ip    = request.remote_ip
  self.user_agent = request.env['HTTP_USER_AGENT']
  self.referrer   = request.env['HTTP_REFERER']
end

#set_parent_deltaObject



19
20
21
# File 'app/models/comment.rb', line 19

def set_parent_delta
  self.post.update_attributes(:delta => true)
end