# -*- encoding : utf-8 -*-
class Article < ActiveRecord::Base
  	include Rails.application.routes.url_helpers

	belongs_to :image_file
	belongs_to :folder


	after_create :after_creation
	

	
	has_one :block, :as => :blockable
	
	belongs_to :folder
	
	validates :title, :presence => true
	validates :slug, :presence => true, :uniqueness => {:scope => :folder_id}
	
	
	def cible_url

		article_path(:slug => self.slug, :folder_slug => self.folder.slug)

		
	end
	
	
	def cible_name
		"Article : #{self.title}"
	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
	
	before_validation do
		self.slug = self.slug.to_slug
		
	end
	
end
