Sha256: a67960f6751f062145f87372b4e7286a5d6e2499a42ee8a271cf881813067e3c
Contents?: true
Size: 491 Bytes
Versions: 18
Compression:
Stored size: 491 Bytes
Contents
module Fae class CrossModelUniquenessValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if options[:model].where(attribute => value).present? record.errors[attribute] << (options[:message] || "has already been taken in #{articlize(options[:model].to_s.downcase)}") end end private def articlize(params_word) %w(a e i o u).include?(params_word[0].downcase) ? "an #{params_word}" : "a #{params_word}" end end end
Version data entries
18 entries across 18 versions & 2 rubygems