public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
insoshi / app / models / blog_post.rb
100644 41 lines (32 sloc) 1.115 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# == Schema Information
# Schema version: 28
#
# Table name: posts
#
# id :integer(11) not null, primary key
# blog_id :integer(11)
# topic_id :integer(11)
# person_id :integer(11)
# title :string(255)
# body :text
# blog_post_comments_count :integer(11) default(0), not null
# type :string(255)
# created_at :datetime
# updated_at :datetime
#
 
class BlogPost < Post
  
  MAX_TITLE = MEDIUM_STRING_LENGTH
  MAX_BODY = MAX_TEXT_LENGTH
  
  attr_accessible :title, :body
  
  belongs_to :blog
  has_many :comments, :as => :commentable, :order => :created_at,
                      :dependent => :destroy
  
  validates_presence_of :title, :body
  validates_length_of :title, :maximum => MAX_TITLE
  validates_length_of :body, :maximum => MAX_BODY
  
  after_create :log_activity
  
  private
  
    def log_activity
      add_activities(:item => self, :person => blog.person)
    end
end