This content has restricted access, please type the password below and get access.
Related to the accepted answer and another answer down the list:
I’m confirming that nanamkim’s fork of custom-err-msg works with Rails 5, and with the locale setup.
You just need to start the locale message with a caret and it shouldn’t display the attribute name in the message.
A model defined as:class Item < ApplicationRecord validates :name, presence: true end
with the following en.yml:en: activerecord: errors: models: item: attributes: name: blank: "^You can't create an item without a name."
item.errors.full_messageswill display:You can't create an item without a name
instead of the usualName You can't create an item without a name
First off, I’ll start with our use-case:
We have a fairly simple form for an item with some complexity. It would have default values derived from the
current_user‘s attributes but would still have the field on its own. Overriding it in Item model feels like overkill (and starts to be a violation of SRP) so we set out to create a PORO model for it. Full code and explanation below the fold.