# -*- encoding : utf-8 -*-
class Page < ActiveRecord::Base


  has_one :menu_item, :as => :menu_content
  
  has_many :blocks, :as => :blockable, :dependent => :destroy
  
  
  #validates :title, :presence => true
  
  HUMAN_NAME = "Page"
  
  after_create :after_creation
  
  def after_creation
      @block = Block.new(:block_name => "general")
    @block.blockable = self
    @block.save
  
  
  end
  
  
  
  def dup
    @new = Page.new(self.attributes)
    @new.id = nil
    @new.save
    @new.blocks.destroy_all
    
    self.blocks.each do |block|
      
      new_b = block.dup
      new_b.blockable = @new
      new_b.save
      
      
    end
    
    @new
    
  end

end
