We are updating from Rails3 to Rails5.
At that time, an error occurred in the method called human_name, and I couldn't find the cause even if I examined it.

The method for generating validation messages in Rails3 is defined as follows:

def validation_message (object)
    if object.errors.count == 1
      t ('activerecord.errors.template.header.one',: model =>object.class.human_name) + ":"
      t ('activerecord.errors.template.header.other',: model =>object.class.human_name,: count =>object.errors.count) + ":"

If i move this code to Rails5

undefined method `human_name 'for #<Class: 0x00007f0d25b4c420>

It will become.

Examined thathuman_namehas been deprecated, but no alternative was found. https://apidock.com/rails/ActiveRecord/Base/human_name/class#996-Use-ModelClass-model-name-human

If i point out that there is an alternative or the implementation is wrong, please let me know.

  • Answer # 1


    If you look into it, human_name is deprecated, but no alternative is found.

    In the link immediately after, there is an alternativeModel.model_name.human.