Sha256: 0b93e844606ce2a3c7525e96c3f7598a51921e033ded6d6f408c9b02e3a79745

Contents?: true

Size: 345 Bytes

Versions: 5

Compression:

Stored size: 345 Bytes

Contents

module Adminos::MoveTo
  def self.included(base)
    base.class_eval do
      sortable
    end
  end

  def move_to(id)
    if id.blank?
      self.move_to_top!
    else
      to_position = self.class.where(id: id).pluck(:position).first
      to_position += 1 if to_position < self.position
      self.insert_at!(to_position)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
adminos-1.0.0.pre.rc.5 lib/adminos/helpers/models/move_to.rb
adminos-1.0.0.pre.rc.4 lib/adminos/helpers/models/move_to.rb
adminos-1.0.0.pre.rc.3 lib/adminos/helpers/models/move_to.rb
adminos-1.0.0.pre.rc.2 lib/adminos/helpers/models/move_to.rb
adminos-1.0.0.pre.rc.1 lib/adminos/helpers/models/move_to.rb