Module: ActiveRecord::Acts::MuckBlog::ClassMethods

Defined in:
lib/active_record/acts/muck_blog.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_muck_blog(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_record/acts/muck_blog.rb', line 10

def acts_as_muck_blog(options = {})
  
  has_many :posts, :as => :contentable, :class_name => 'Content'
  belongs_to :blogable, :polymorphic => true

  has_friendly_id :title, :use_slug => true, :scope => :get_blog_scope
  
  validates_presence_of :title
  
  named_scope :by_newest, :order => "created_at DESC"
  named_scope :by_oldest, :order => "created_at ASC"
  named_scope :recent, lambda { { :conditions => ['created_at > ?', 1.week.ago] } }
                    
  class_eval <<-EOV
    # prevents a user from submitting a crafted form that changes audit values
    attr_protected :created_at, :updated_at
  EOV

  include ActiveRecord::Acts::MuckBlog::InstanceMethods
  extend ActiveRecord::Acts::MuckBlog::SingletonMethods
  
end