You need to add allow_nil: true
.
http://guides.rubyonrails.org/active_record_validations.html#allow-nil
質問
how to validate a model with one integer property say customer_id in order table which allows customer_id but if its available it should be great then 0
class Order < ActiveRecord::Base
validates :name, presence: true, length: {minimum: 3, maximum: 10}
validates :customer_id, numericality: {greater_than_or_equal_to: 1}, presence: false
end
i did it using above but it is not accepting null values in number.
解決
You need to add allow_nil: true
.
http://guides.rubyonrails.org/active_record_validations.html#allow-nil