Automatically add sort order.
This commit is contained in:
parent
690b219da0
commit
9abe9b71b6
|
@ -20,6 +20,16 @@ class Album
|
||||||
has_many :album_colors, :autosave => true, :dependent => :destroy
|
has_many :album_colors, :autosave => true, :dependent => :destroy
|
||||||
accepts_nested_attributes_for :album_images, :allow_destroy => true
|
accepts_nested_attributes_for :album_images, :allow_destroy => true
|
||||||
accepts_nested_attributes_for :album_colors, :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)
|
def self.find_by_param(input)
|
||||||
self.find_by(uid: input)
|
self.find_by(uid: input)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue