Class: BitCore::Slideshow
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BitCore::Slideshow
- Defined in:
- app/models/bit_core/slideshow.rb
Overview
A collection of ordered Slides.
Instance Method Summary collapse
Instance Method Details
#add(slide_params) ⇒ Object
18 19 20 21 22 23 |
# File 'app/models/bit_core/slideshow.rb', line 18 def add() = .build() .position = .count + 1 end |
#remove(slide) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'app/models/bit_core/slideshow.rb', line 25 def remove() return false unless .destroy (.position + 1...last.position).each do |pos| .find_by_position(pos).update(position: pos - 1) end true end |
#sort(ordered_ids) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/models/bit_core/slideshow.rb', line 35 def sort(ordered_ids) self.class.transaction do self.class.connection.execute "SET CONSTRAINTS " \ "bit_core_slide_position DEFERRED" ordered_ids.each_with_index do |id, idx| .find(id).update_attribute(:position, idx + 1) end end end |