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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs