Fix sortable when there's no record

This commit is contained in:
chris 2013-06-13 14:33:15 +08:00
parent 96fc5ceea3
commit c1bd135595
1 changed files with 1 additions and 1 deletions

View File

@ -23,7 +23,7 @@ module Mongoid
def set_sort_number
if self.new? && self.sort_number.nil?
last_record = self.class.desc(:sort_number).first
if last_record.sort_number
if last_record && last_record.sort_number
self.sort_number = (last_record.sort_number + 10) / 10 * 10
else
self.sort_number = 10