How to tell Rails how to use the abbreviation correctly?

I have a field called suiin one of my models. This means "Standard User ID". When there are validation errors in the field, Rails prints "Sui is required" or "Sui is already done."

How can I tell Rails what 'sui'.titleizeis "SUI"? I looked at Inflector.human, but this is not entirely correct.

+5
source share
2 answers

In such cases, I use the custom_err_msg plugin. Since it is installed, you can provide custom error messages as follows:

validates_presence_of :sui, :message => '^SUI is required'

^ , Rails .

EDIT: i18n_label, , - ( ). :

<%= f.label :sui %>
YourModel.human_attribute_name "sui"

.

+7

, ActiveSupport:: Inflector, titleize. inflections .

# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym 'SUI'
end

, . titleize , "SUI". Rails, :

> "sui".titleize
=> "SUI"

, .

+2

All Articles