Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate a field only if another has been filled out?

How would I validate a field only if another has been filled out In Ruby on Rails 2.3.5?

like image 310
Yuval Karmi Avatar asked Dec 12 '22 23:12

Yuval Karmi


1 Answers

class Model < ActiveRecord::Base

  validates_presence_of :address, :if => :city?

end

:address and :city are both attributes of Model.

like image 104
Simone Carletti Avatar answered May 19 '23 11:05

Simone Carletti