Sha256: 994a93a35a887b0f76990058bf7ec68afcb8a852a7113ed390e0109491e391e6
Contents?: true
Size: 676 Bytes
Versions: 7
Compression:
Stored size: 676 Bytes
Contents
# If you want to use this concern, you need to add an integer field 'position' # to the model. module Concerns module Sortable extend ActiveSupport::Concern included do acts_as_list default_scope ->{ order(:position) } end module ClassMethods def sortable(*args) acts_as_list *args end end def set_position(new_position, parent_id = nil) if respond_to?(:draggable?) && !draggable? || position == new_position.to_i return false end if respond_to?(:parentable?) && parentable? update_attribute :parent_id, parent_id end set_list_position new_position end end end
Version data entries
7 entries across 7 versions & 1 rubygems