Skip to content

Instantly share code, notes, and snippets.

@daviddavis
Last active December 15, 2015 15:49
Show Gist options
  • Select an option

  • Save daviddavis/5285204 to your computer and use it in GitHub Desktop.

Select an option

Save daviddavis/5285204 to your computer and use it in GitHub Desktop.
class Distributor
belongs_to :environment
# ...
validate name_uniq_in_org
def name_uniq_in_org
others = self.where(:name => self.name).join(:environment).
where("enivronment.organization_id" => self.environment.organization_id)
others.where("id != ?", self.id) if self.id
errors.add(:base, "name already taken") if others.any?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment