class ActiveModelValidators::NumericArrayValidator
Validator of numerical array¶ ↑
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
Adds error if there an attribute with not a numerical array provided
-
record
- ActiveRecord model -
attr
- model attribute to store an array -
value
- value, supposed to be a numerical array
Example¶ ↑
class MyModel < ActiveRecord::Base validates :my_atribute, :'active_model_validators/numeric_array' => true end my_model_instance = MyModel.create(my_attribute: [1,2,3]) my_model_instance.valid? # => true my_model_instance.my_attribute = 'bar' my_model_instance.valid? # => false
# File lib/active_model_validators/numeric_array_validator.rb, line 21 def validate_each(record, attribute, value) unless array_numeric?(value) record.errors.add(attribute, options[:message] || numeric_message) end end