Module: Polymorph::Orderable::ClassMethods
- Defined in:
- lib/polymorph/orderable.rb
Instance Method Summary collapse
Instance Method Details
#ensure_resource(id_or_resource) ⇒ Object
16 17 18 19 |
# File 'lib/polymorph/orderable.rb', line 16 def ensure_resource(id_or_resource) return id_or_resource if id_or_resource.is_a? self find(id_or_resource) end |
#reorder(*new_order) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/polymorph/orderable.rb', line 15 def reorder(*new_order) def ensure_resource(id_or_resource) return id_or_resource if id_or_resource.is_a? self find(id_or_resource) end new_order.flatten.compact.map.each_with_index do |id_or_resource, index| resource = ensure_resource(id_or_resource) position = index * 10 + 10 resource.update_attribute(:position, position) [resource, position] end end |