Reputation: 45943
class Foo
include Mongoid::Document
field :bars, type:Array
end
How to validate that the bars
array is not empty?
Upvotes: 2
Views: 4199
Reputation: 239885
Try the standard presence validator:
class Foo
include Mongoid::Document
field :bars, type: Array
validates :bars, presence: true
end
This works because the presence
validator uses the blank?
method to check the attribute during validation.
Upvotes: 4