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

	after_create :after_creation
	

	
	has_one :block, :as => :blockable
	
	has_many :articles
	
	validates :title, :presence => true
	validates :folder_type_id, :presence => true
	validates :slug, :presence => true, :uniqueness => true
	
	FOLDER_TYPES = [["Dossier thématique",1], ["Prestation",2]]
	
	
	def cible_url

		folder_path(:slug => self.slug)

		
	end
	
	def cible_name
		"Dossier : #{self.title}"
	end
	
	def after_creation
	    @block = Block.new(:block_name => "en tête")
		@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
