Re: errors.add, setting the whole message

Sjoerd Andringa
Fri, 24 Sep 2010 08:09:53 -0000

If you''re using I18n (which I think is always a good idea, even if
you''re only using one language) you can do two things:

1. Define a translation for the job_role_id_short attribute:

In app_root/config/locales/en.yml:

en:
    activerecord:
        attributes:
            my_model:
                job_role_id_short: "Job"

This will not only fix "Job Role Short" in the error message but
anywhere else where Rails tries to convert that attribute in a human
readable string. If you dont want this, go for the alternative:

2. Override the default error message for this kind of error on this
particular attribute (Also see documentation for
http://apidock.com/rails/ActiveRecord/Error/generate_full_message):

In app_root/config/locales/en.yml:

en:
    activerecord:
        errors:
            full_messages:
                job_role_id_short:
                    blank: "Job cannot be blank"