Ruby on rails rails 4活动记录中的自定义字符串错误消息

Ruby on rails rails 4活动记录中的自定义字符串错误消息,ruby-on-rails,activerecord,ruby-on-rails-4,rails-activerecord,Ruby On Rails,Activerecord,Ruby On Rails 4,Rails Activerecord,我在yml文件中定义了一条activerecords错误消息: en: activerecord: errors: models: participant: attributes: base: file_type_invalid: This file type %{file_name} is not acceptable 因此,错误消息应显示为此文件类型xyz.zip不可接受 在相应

我在yml文件中定义了一条activerecords错误消息:

en:
  activerecord:
    errors:
      models:
        participant:
          attributes:
            base:
              file_type_invalid: This file type %{file_name} is not acceptable
因此,错误消息应显示为此文件类型xyz.zip不可接受

在相应的模型中,我为该错误添加了如下错误:

错误。添加:基本,:文件\u类型\u无效 在这里,我如何将文件名传递给错误消息?这行不通

错误。添加:基本,:文件类型无效,文件名:'xyz.zip'


那么如何解决这个问题呢?请注意,文件名不是该列的属性或值。

您应该能够直接使用I18n:

errors.add(:base, I18n.translate('activerecord.errors.models.participant.attributes.base.file_type_invalid', file_name: 'some filename'))
它有点违背了自动查找的目的,但据我所知,add方法不支持错误字符串的参数