Class: Adminpanel::Gallery

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/adminpanel/gallery.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.display_name ⇒ Object



49
50
51
# File 'app/models/adminpanel/gallery.rb', line 49

def self.display_name
  "Galería"
end

.form_attributes ⇒ Object



43
44
45
46
47
# File 'app/models/adminpanel/gallery.rb', line 43

def self.form_attributes
  [
    {'file' => { 'name' => 'Archivo' }}
  ]
end

Instance Method Details

#move_to_better_position ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/adminpanel/gallery.rb', line 16

def move_to_better_position
  if position > 1
  conflicting_gallery = Gallery.find_by_position(position - 1)
  update_attribute(:position, position - 1)
  conflicting_gallery.update_attribute(
    :position, conflicting_gallery.position + 1
    )
  true
  else
    false
  end
end

#move_to_worst_position ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/adminpanel/gallery.rb', line 29

def move_to_worst_position
  records = Gallery.count
  if position < records
  conflicting_gallery = Gallery.find_by_position(position + 1)
  update_attribute(:position, position + 1)
  conflicting_gallery.update_attribute(
    :position, conflicting_gallery.position - 1
    )
  true
  else
    false
  end
end