ruby on rails - Validation two length options -
ruby on rails - Validation two length options -
i'm validating model field number.
i seek accomplish numbers 8 or 6 characters long allowed.
but code error:
code:
validates :number, length: { is: [6,8] } error:
argumenterror (:is must nonnegative integer or infinity): app/models/patient.rb:6:in `<class:patient>' app/models/patient.rb:1:in `<top (required)>' app/controllers/patients_controller.rb:38:in `create' how should alter code? thanks
a custom validation might like:
class patientvalidator def validate(patient) patient.errors.add(:number, "bad length!") unless [6, 8].include? patient.number end end then, in patient:
validates_with patientvalidator ruby-on-rails ruby-on-rails-3 validation ruby-on-rails-4
Comments
Post a Comment