class Article < ActiveRecord::Base belongs_to :image_file validates :title, :presence => true validates :slug, :presence => true, :uniqueness => true has_one :block, :as => :blockable has_many :comments, :as => :commentable has_many :enabled_comments,:conditions => {:enabled => true}, :source => :comments, :as => :commentable after_create :after_creation before_validation do self.slug = self.slug.to_slug end def after_creation @block = Block.new(:block_name => "Contenu") @block.blockable = self @block.save ContentType.all.each do |content_type| @block.content_types << content_type end end scope :recents, where("enabled = ?",true ).order("published_at DESC") end