Ryan -
Thanks for the response.
Did you set the field to be an integer?
Set it how? In the database? In the DB is in an INT.
If so, then you shouldn’t need the :only_integer option specified.
Fair enough, except that these validations are at the model level and, I assume, without them, my user could enter a fractional number and then have ActiveRecord silently convert that to an INT at save time, whereas I’d like a more proactive validation message given to them if they should try this.
Also, how is the users value being passed in?
Well, currently I’m doing this in unit tests.
Are you trying to validate the presence of, rather than the numericality of the users, or is users automatically set to 0 as the default in your table?
No default value at the database level.
Have you tried taking :allow_nil out?
Yes, but…two things:
1) that doesn't help, and
2) I want to allow nil for this value, but when the value is provided, I want this greater_than validation to apply, which seems like a valid scenario
Here’s the full model:
class ServicePlan < ActiveRecord::Base
has_many :accounts
validates_presence_of :name, :monthly_service_charge
validates_length_of :name, :maximum => 255
validates_uniqueness_of :name, :case_sensitive => false
validates_numericality_of :monthly_service_charge, :greater_than_or_equal_to => 0, :message => “TBD”
validates_numericality_of :count_sheets_per_week, :greater_than => 0, :only_integer => true, :allow_nil => true, :message => “TBD”
validates_numericality_of :users, :greater_than => 0, :only_integer => true, :allow_nil => true, :message => “TBD”
validates_numericality_of :report_recipients, :greater_than => 0, :only_integer => true, :allow_nil => true, :message => “TBD”
validates_numericality_of :templates, :greater_than => 0, :only_integer => true, :allow_nil => true, :message => “TBD”
end