0
我想验证在保存我的活动时至少输入了一个选项。 Option是一个嵌入式的mongoid文档。我怎样才能做到这一点?验证嵌入式文档的存在吗?
class Event
include Mongoid::Document
field :name, type: String
field :description, type: String
field :date, type: Date
embeds_many :invitees, cascade_callbacks: true
embeds_many :participants, cascade_callbacks: true
embeds_many :comments, cascade_callbacks: true
embeds_many :options, cascade_callbacks: true
has_one :owner, :class_name => "User"
validates :name, :date, :presence => true
accepts_nested_attributes_for :options, autosave: true, allow_destroy: true
accepts_nested_attributes_for :participants, autosave: true, allow_destroy: true
accepts_nested_attributes_for :comments, autosave: true, allow_destroy: true
accepts_nested_attributes_for :invitees, autosave: true, allow_destroy: true
accepts_nested_attributes_for :owner, autosave: true, allow_destroy: true
end
thx会试用它!干杯 – Mike