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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -