Class: Comment

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



12
13
14
# File 'lib/forge/app/models/comment.rb', line 12

def controller
  @controller
end

#subscribeObject

Returns the value of attribute subscribe.



12
13
14
# File 'lib/forge/app/models/comment.rb', line 12

def subscribe
  @subscribe
end

Class Method Details

.create_comment(object, session) ⇒ Object



25
26
27
# File 'lib/forge/app/models/comment.rb', line 25

def self.create_comment(object, session)
  session.blank? ? Comment.new(:commentable_type => object.class.to_s, :commentable_id => object.id) : Comment.new(session)
end

Instance Method Details

#approveObject



43
44
45
# File 'lib/forge/app/models/comment.rb', line 43

def approve
  self.approved = true
end

#approve!Object



33
34
35
36
# File 'lib/forge/app/models/comment.rb', line 33

def approve!
  self.approved = true
  return self.save
end

#author_urlObject



47
48
49
50
51
52
53
# File 'lib/forge/app/models/comment.rb', line 47

def author_url
  if super.blank? || super.match('http://') || super.match('https://')
    return super
  else
    return 'http://' + super
  end
end

#emailObject



29
30
31
# File 'lib/forge/app/models/comment.rb', line 29

def email
  self.author_email
end

#error_messageObject



63
64
65
66
67
# File 'lib/forge/app/models/comment.rb', line 63

def error_message
  errors = []
  self.errors.full_messages.each { |error| errors << "<li>#{error}</li>" }
  return "<div class='errorExplanation' id='errorExplanation'>There were problems with the following fields:<ul>#{errors}<ul></div>"
end

#short?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/forge/app/models/comment.rb', line 55

def short?
  content.length > 100 ? true : false
end

#short_commentObject



59
60
61
# File 'lib/forge/app/models/comment.rb', line 59

def short_comment
  "#{self.content[0..100]}..."
end

#spam?Boolean

TODO: put this back in has_rakismet

Returns:

  • (Boolean)


4
# File 'lib/forge/app/models/comment.rb', line 4

def spam?; false; end

#unapprove!Object



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

def unapprove!
  self.approved = false
  return self.save
end