Sha256: 304f00e2da451ec30fc01e3e285263196dd88a1995d1041ddd371ada35de090a
Contents?: true
Size: 517 Bytes
Versions: 15
Compression:
Stored size: 517 Bytes
Contents
# frozen_string_literal: true class FormElement < ApplicationRecord belongs_to :element, optional: true before_create :set_last_position def set_last_position position = FormElement.all.order(position: :desc)&.first&.position self.position = position.blank? ? 1 : position + 1 end def self.sort_elements(id_array) transaction do logger.debug { id_array.inspect } id_array.each_with_index do |elm_id, i| FormElement.update(elm_id, position: i) end end end end
Version data entries
15 entries across 15 versions & 1 rubygems