Module: Adminpanel::SortableGallery

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/adminpanel/sortable_gallery.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#move_to_position(new_position) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/concerns/adminpanel/sortable_gallery.rb', line 40

def move_to_position(new_position)
  if new_position < position
    # search for better elements and downgrade them
    self.class.in_better_position(
      self.position,
      new_position,
      self.model_id
    ).update_all('position = position + 1')
  else
    # search for worster elements and upgrade them
    self.class.in_worst_position(
      self.position,
      new_position,
      self.model_id
    ).update_all('position = position - 1')
  end
  self.update(position: new_position)
end

#nameObject

we should detect if the name isn’t defined in the class



60
61
62
# File 'app/models/concerns/adminpanel/sortable_gallery.rb', line 60

def name
  I18n.t('gallery.image')
end