[LRUG] Rails: presence validation and i18n

Andrew Stewart boss at airbladesoftware.com
Mon Sep 21 08:11:42 PDT 2015


Hello LRUG!

In a model in my Rails app I have a model like this:

class Person
  belongs_to :company
  validates :age, presence: true
  validates :name, presence: {scope: company_id}
end

When somebody submits a new person's form without filling in any fields, they get:

- a "can't be blank" error message for the age field
- a "translation missing: en.company_id.activerecord.errors.models.person.attributes.name.blank" message for the name field.

I would rather the name field had a simple "can't be blank" error message instead.

I can't figure out why the scope validation option alters the attribute's i18n key, and how to prevent it...

Thanks!

Andy Stewart


More information about the Chat mailing list