lib/carte/server/models/card.rb in carte-server-0.0.5 vs lib/carte/server/models/card.rb in carte-server-0.0.6

- old
+ new

@@ -3,10 +3,11 @@ module Models class Card include Mongoid::Document include Mongoid::Timestamps include Mongoid::Attributes::Dynamic + include Mongoid::Document::Taggable field :title, type: String field :new_title, type: String field :content, type: String @@ -27,11 +28,13 @@ def version self.histories.size + 1 end before_validation(on: :update) do - self.title = self.new_title - self.new_title = nil + if self.new_title + self.title = self.new_title + self.new_title = nil + end end def self.sample(size=1) self.in(id: (1..self.count).to_a.sample(size)) end