Rails: validation on two fields -
one quick question. have 2 fields pick_up , delivery. want user enter 1 of 2 fields while submitting form. means:
validates pick_up or delivery, :presence => :true.
at least 1 should present.
how write validation?
validate :pickup_or_delivery
def pickup_or_delivery if [self.pick_up, self.delivery].compact.blank.size == 0 errors[:base] << ("please select 1 option") end end
Comments
Post a Comment