You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
so, to be honest, i'm not 100% convinced this is really a bug, but figured i'd raise it, just in case it is. please excuse me if this has been discussed previously -- i was unable to find any mention of it in issues.
so -- if you have a non-null integer field that has a validation like:
By default, numericality doesn't allow nil values. You can use allow_nil: true option to permit it. For Integer and Float columns empty strings are converted to nil.
so in the example above allow_nil: false should not really even be necessary as it is the default. so the existence of the numericality: validator -- in the absence of allow_nil: true should suffice to be a presence validator for non-null integer columns, yes?
if my assertion is correct, i'd consider adding a PR to address this, once i get my fingers into the code. i welcome discussion. thanks for reading!
The text was updated successfully, but these errors were encountered:
@vanharen, thank you for your comment. Discussion is always much appreciated!
I don't think treating allow_nil: false (which is the default as you mentioned) is a good idea. Technically, it does report a validation error, but we want to help application developers deliver the best possible user experience.
In this case, if you leave rank empty you'll get an error of type :not_a_number with a message "Rank is not a number". I think this is a very confusing error from a user's perspective, especially that it'll additionally be shown when the field contains an invalid value.
then leaving rank blank will result in two messages ("Rank is blank", "Rank is not a number"), which is confusing. In this case, better UX can be achieved by adding allow_nil to numericality validator (and I'm working on a detector to do just that).
first off, thanks for the gem! very handy!
so, to be honest, i'm not 100% convinced this is really a bug, but figured i'd raise it, just in case it is. please excuse me if this has been discussed previously -- i was unable to find any mention of it in issues.
so -- if you have a non-null integer field that has a validation like:
then it is my belief that this should suffice as a presence validator even though
presence: true
is not explicitly listed in the validator. one could include this but it is redundant, imho, based on the following (from https://guides.rubyonrails.org/active_record_validations.html#numericality)so in the example above
allow_nil: false
should not really even be necessary as it is the default. so the existence of thenumericality:
validator -- in the absence ofallow_nil: true
should suffice to be a presence validator for non-null integer columns, yes?if my assertion is correct, i'd consider adding a PR to address this, once i get my fingers into the code. i welcome discussion. thanks for reading!
The text was updated successfully, but these errors were encountered: