I am using Ruby 1.9.3-p448 and Rails 3.2.13. I have this simple model with a float format validation:
class User
include Mongoid::Document
include Mongoid::Timestamps
field :height, type: Float
field :weight, type: Float
validates :height, presence: true, format: { with: /[-+]?[0-9]*\.?[0-9]+/ }
validates :weight, presence: true, format: { with: /[-+]?[0-9]*\.?[0-9]+/ }
end
If i run this code:
test = User.new(height:"hi", weight:"try")
It gives me the following result:
#<User _id: 51f67b49781018056b000008, created_at: nil, updated_at: nil, height: 0.0,width: 0.0>
Why does mongoid put a 0.0 value if I put a string? I was expecting a validation error.