Check if address exists


#1

how do you write your method to check if your recipient and zip exists for the same ID because you don’t want to repeat? At first I tried the Address.where(:recipient => self.recipient) && Address.where(:zip => self.zip), but that didn’t work. Any ideas?


#2

you can use validations in the Address model

# validate
 validates :recipient, :zip, uniqueness: { scope: :id  }