mongoid/mongoid — Issue #1563: How can I validate a hash field?
Author: HungYuHei
Created: 2012-01-07 08:05:45+00:00
State: open

I want to validate one of a hash field's value whether it's a number

for example:

class Foo
include Mongoid::Document
field :bar, :type => Hash

validates_numericality_of "bar['counter']"
end

f = Foo.new
f.bar = { 'counter' => 'string' }
f.save # should return **false**

f.bar = { 'counter' => 1 }
f.save # should return **true**