diff --git a/app/models/album.rb b/app/models/album.rb index 325b4a6..66486b4 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -20,6 +20,16 @@ class Album has_many :album_colors, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :album_images, :allow_destroy => true accepts_nested_attributes_for :album_colors, :allow_destroy => true + before_save do |record| + if record.order.nil? || record.order == -1 + topest_order = Album.all.pluck(:order).sort{|a,b| a.to_i<=>b.to_i}.first + if topest_order.nil? || topest_order == 0 + record.order = -2 + else + record.order = topest_order - 1 + end + end + end def self.find_by_param(input) self.find_by(uid: input) end