Module: ActiveRecord::AdminpanelExtension
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/adminpanel/active_record/adminpanel_extension.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#move_to_better_position ⇒ Object
instance methods.
- #move_to_worst_position ⇒ Object
Instance Method Details
#move_to_better_position ⇒ Object
instance methods
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 5 def move_to_better_position if self.position > 1 conflicting_gallery = self.class.where(self.class.relation_field => self.send(self.class.relation_field)).find_by_position(position - 1) self.update_attribute(:position, self.position - 1) conflicting_gallery.update_attribute( :position, conflicting_gallery.position + 1 ) true else false end end |
#move_to_worst_position ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 18 def move_to_worst_position records = self.class.count if self.position < records conflicting_gallery = self.class.where(self.class.relation_field => self.send(self.class.relation_field)).find_by_position(position + 1) update_attribute(:position, self.position + 1) conflicting_gallery.update_attribute( :position, conflicting_gallery.position - 1 ) true else false end end |