Hopstream Hopstream -3 years ago 60
Ruby Question

Rails validation required numericality even though presence is not set to true

I'm trying to save a record which doesn't have one field set -- which has a validate numericality in the models. Even though the presence is not required in the validation, it's still throwing an error that the field is not a number.


validates :network_id, :numericality => true

Code to that is saving model:

networks.each do |network|
network.url = network.raw_data.link


Validation failed: Network is not a number

Answer Source
validates :network_id, :numericality => true, :allow_nil => true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download