Class: PresenceDefaultLocaleValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/models/presence_default_locale_validator.rb

Overview

Validate whether the default locale of a translated attribute is present

validates    :content, presence_default_locale: true

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
10
# File 'app/models/presence_default_locale_validator.rb', line 5

def validate_each(record, attribute, value)
  attribute_locale = "#{attribute.to_s}_#{Account.current.preferred_default_locale}"
  if record.send(attribute_locale).blank?
    record.errors.add attribute_locale, I18n.t("errors.messages.blank")
  end
end