Ruby on Rails Wednesday, September 16, 2015

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 by

validates :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?

In my database, I cannot restrict NULL values for this column. The model I am working on is a child of another, where the main model does not require # of extensions, but this child model does.

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

Thank you for the time and help!

--
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/96a55344-46f9-4d49-9981-e4e9fff73a99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment