I have a field called sui
in one of my models. It stands for "Standard User Identifier." When there are validation errors on the field, Rails prints "Sui is required" or "Sui is already taken."
How can I tell Rails that 'sui'.titleize
is "SUI"? I looked at Inflector.human
, but that isn't quite right.
In such cases I use custom_err_msg plugin. As it is installed you can give custom error messages like this:
validates_presence_of :sui, :message => '^SUI is required'
When you put ^ at the begining then Rails don't put field name.
EDIT: There is another plugin i18n_label used for translations, but with it you can in very simple way replace a name of your field with something nicer (on plugin page there is an example). It will substitute name in:
<%= f.label :sui %>
YourModel.human_attribute_name "sui"
and in error messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With