coreyward
coreyward

Reputation: 80041

How can I use I18N translations with ActiveModel::Validations outside of ActiveRecord?

The I18n scopes provided by the Rails Guide are specific to utilization of ActiveModel::Validations within ActiveRecord objects. For example:

en:
  activerecord:
    errors:
      models:
        some_model:
          attributes:
            name:
              blank: "Please enter your full legal name."

This won't work when using ActiveModel::Validations in this way:

class SomeModel
  include ActiveModel::Validations
  validates :name, presence: true
end

Instead the framework default “can't be blank" is used.

How can this be resolved?

Upvotes: 2

Views: 1186

Answers (1)

coreyward
coreyward

Reputation: 80041

Substituting activemodel for activerecord fixes this and allows all subsequent scopes to work. Example:

en:
  activemodel: # <---
    errors:
      models:
        message:
          attributes:
            name:
              blank: "Please enter your name."

Upvotes: 8

Related Questions