# -*- encoding : utf-8 -*-
class Slide < ActiveRecord::Base
	belongs_to :image_file
	belongs_to :slider
	belongs_to :cible, :polymorphic => true
	accepts_nested_attributes_for :cible
	validates :title, :presence => true
	
	before_create do 
		slides = Slide.where(:slider_id => self.slider_id).order("position desc")
		slides[0] ? position = slides[0].position.to_i + 1 : position = 1
		
		self.position = position
		
		
	end

end
