Sha256: c019b4388f7343302c9ad1f018ea8aff209316a674cd8aa224385678b49b1e77

Contents?: true

Size: 549 Bytes

Versions: 16

Compression:

Stored size: 549 Bytes

Contents

# Validate whether the default locale of a translated attribute is present
#   validates    :content, presence_default_locale: true
#------------------------------------------------------------------------------
class PresenceDefaultLocaleValidator < ActiveModel::EachValidator
  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
end
 

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dm_core-4.2.3.10 app/models/presence_default_locale_validator.rb
dm_core-4.2.3.9 app/models/presence_default_locale_validator.rb
dm_core-4.2.3.8 app/models/presence_default_locale_validator.rb
dm_core-4.2.3.7 app/models/presence_default_locale_validator.rb
dm_core-4.2.3.6 app/models/presence_default_locale_validator.rb
dm_core-4.2.3.5 app/models/presence_default_locale_validator.rb
dm_core-4.2.3.4 app/models/presence_default_locale_validator.rb
dm_core-4.2.3.3 app/models/presence_default_locale_validator.rb
dm_core-4.2.3.2 app/models/presence_default_locale_validator.rb
dm_core-4.2.3.1 app/models/presence_default_locale_validator.rb
dm_core-4.2.3 app/models/presence_default_locale_validator.rb
dm_core-4.2.2.3 app/models/presence_default_locale_validator.rb
dm_core-4.2.2.2 app/models/presence_default_locale_validator.rb
dm_core-4.2.2.1 app/models/presence_default_locale_validator.rb
dm_core-4.2.2 app/models/presence_default_locale_validator.rb
dm_core-4.2.1.5 app/models/presence_default_locale_validator.rb