Sha256: d19bada7108a79898085d58f7dae3c46a0ebcf51163c58aba0e84a6d130220d4
Contents?: true
Size: 737 Bytes
Versions: 9
Compression:
Stored size: 737 Bytes
Contents
module Callbacks module Form class FieldBeforeUpdate include Restrictor def call if m.position_was < m.position # move list range downward range = (m.position_was + 1)..m.position reverse = false else # move list range upward range = m.position..(m.position_was - 1) reverse = true end query = m.fields.where(position: range) if reverse query = query.reverse_order end query.each.with_index do |field, i| position = reverse ? m.position_was - i : m.position_was + i field.update_column(:position, position) end m.update_header end end end end
Version data entries
9 entries across 9 versions & 1 rubygems