ActiveRecord labels using I18n

0

I have the following code:

pt-BR.yml

activerecord:
  attributes:
    city:
      codigo_municipio: "Código do município"

View

= label(:city, :codigo_municipio)

Expected result:

# => <label for="cities_codigo_municipio">Código do municipio</label>

Result obtained:

# => <label for="cities_codigo_municipio">Codigo municipio</label>

According to documentation all correct.

    
asked by anonymous 10.04.2015 / 15:09

1 answer

0

The label method uses only the helper translation:

helpers:
  label:
    city:
      codigo_municipio: "Código do município"

If you already have the translation in activerecord.attributes it is not convenient to duplicate the code to do the translation, so to solve this problem, just use human_attribute_name , see example below:

= City.human_attribute_name(:codigo_municipio)

In this way rails will use activerecord.attributes instead of helpers.label

    
10.04.2015 / 19:01