Why isn't my AR model validation error message format working?

I’ve got this in my en.yml:

  activerecord:
    attributes:
      my_model:
        my_attr: "BLUBO"
    errors:
      models:
        my_model:
          format: "%{message}"
          attributes:
            my_attr:
              my_error: "Hello hello"

I expect the full message for the validation error to be only “Hello hello”, but it is “BLUBO Hello hello”. Why is Rails ignoring my custom format?

Edit: it makes no difference if I move the “format” inside the attribute, like this:

    errors:
      models:
        my_model:
          attributes:
            my_attr:
              format: "%{message}"
              my_error: "Hello hello"

Edit 2: Perhaps I should clarify that I am adding this error to my model through a custom validation with errors.add(:my_attr, :my_error).

Ok, I found it: you must set config.active_model.i18n_customize_full_message = true in config/application.rb for custom error message formats to be used. Not sure how I missed that.

1 Like