Rails I18n: How to add a error translation key which is common for all model base errors? -
in current application use i18n. have add :base error key should common models. ex: add :common_error in 1 place in en.yml file , use follows,
@user.errors.add(:base, :common_error) @post.errors.add(:base, :common_error) ..and on i'm worried if should add :common_error key in models there more model present in application.
my current en.yml file looks follows,
en-uk: activerecord: errors: <<: *errors models: user: attributes: base: some_key: "" post: attributes: base: some_key: "" i'm not sure if there simple solution haven't found. ideas appriciated. in advance!
simply don't use relative translation key -
@user.errors.add(:base, t(:common_error) ) if pass symbol errors.add translation uses scope of model.
Comments
Post a Comment