Check if address exists

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?

you can use validations in the Address model

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