Sha256: ed577c9ffb067853b1f05d7bfa4d73863096a8745944df53905ebae80cf014a1
Contents?: true
Size: 957 Bytes
Versions: 8
Compression:
Stored size: 957 Bytes
Contents
module AbAdmin module Concerns module Validations class UniqTranslationValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) (options[:locales] || ::I18n.available_locales).each do |l| next if record.read_attribute(attribute, locale: l).blank? records_scope = record.class.const_get(:Translation).where("#{record.class.model_name.singular}_id != #{record.id || 0}") same = records_scope.where(name: record.read_attribute(attribute, locale: l), locale: l.to_s).exists? record.errors.add("#{attribute}_#{l}", :taken) if same end end end class AssetValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if Array(record.fileupload_asset(attribute)).all?{|a| a.new_record? } record.errors.add(attribute, :blank) end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems