app/models/carousel/slide.rb in comfy_carousel-0.0.0 vs app/models/carousel/slide.rb in comfy_carousel-0.0.1

- old
+ new

@@ -1,23 +1,27 @@ class Carousel::Slide < ActiveRecord::Base - has_attached_file :slide, - :styles => { - :slide => "450x315#", - :edit_page => "150x150>" - } - - attr_accessible :description, - :url, - :slide, - :title, - :sort - - # -- Validations ---------------------------------------------------------- + self.table_name = :carousel_slides - validates :description, - :url, - :title, - :sort, + has_attached_file :file + + # -- Relationships -------------------------------------------------------- + belongs_to :carousel + + # -- Callbacks ------------------------------------------------------------ + before_create :assign_position + + # -- Validations ---------------------------------------------------------- + validates :carousel_id, :label, :presence => true + + # -- Scopes --------------------------------------------------------------- + default_scope order('carousel_slides.position') + +protected + + def assign_position + max = carousel.slides.maximum(:position) + self.position = max ? max + 1 : 0 + end end