Ruby on Rails
Thursday, September 17, 2015
On Wed, Sep 16, 2015 at 9:54 AM, Hunter Stevens <onebree@gmail.com> wrote:
Hello. I know the title may be broad, but I am not sure how else to put it.
I am writing a model, in which the attribute "number_of_extensions" needs 2 things:
1. It is required for this model
2. It must be a whole, positive number
I know I can do this simply byvalidates :number_of_extensions, presence: true, numericality: { only_integer: true }
However, if I validate for JUST numericality, is it assumed that the attribute SHOULD be present?
That is so; there is an option to allow nil or blank, but it is false by default. As it needs to be positive, you should also specify `greater_than: 0` in the options hash.
Also, while I am talking about validations, I have another question:
I know that the following type of validations is not in the docs anymore, but it is still supported. Would the following line be possible?validates_numericality_of :number_of_extensions, :number_of_sidecars, :number_of_phones, only_integer: true
I'm pretty sure that is still in:
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHUC_t8zcK5Ge%3Ds6RxCt9OVgBY6VMzN5Y8C5UR58WAT4X%2BWLYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment