'How to localize ActiveModel::Error message

When I validate a model I get the following error

<ActiveModel::Errors:0x007ffecf1c9460 
@base=#<Post id: nil, created_at: nil, label_id: nil, user_id: 3>,
@messages={:label=>["can't be blank"]},
@details={:label=>[{:error=>:blank}]}>

How can I customize the error message?

From my understanding, the following should work

en:
  activerecord:
    errors:
      models:
        post:
          attributes:
            label:
              blank: do not like it

However, I still get the default error message.



Solution 1:[1]

It's ActiveModel, not ActiveRecord you want to localize:

en:
  activemodel:
    errors:
      models:
        post:
          attributes:
            base:
              label:
                blank: do not like it

From docs:

If you are using a class which includes ActiveModel and does not inherit from ActiveRecord::Base, replace activerecord with activemodel.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1