Question

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.

Was it helpful?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top