From c1bd135595ace8a22f25e3161c19a3f2a9d7836b Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 13 Jun 2013 14:33:15 +0800 Subject: [PATCH] Fix sortable when there's no record --- app/models/mongoid/sortable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/mongoid/sortable.rb b/app/models/mongoid/sortable.rb index b22dce08..8f00a8cc 100644 --- a/app/models/mongoid/sortable.rb +++ b/app/models/mongoid/sortable.rb @@ -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