Activerecord Labels using I18n

Asked

Viewed 122 times

0

I have the following code:

en.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 the documentation it’s all right.

1 answer

0


The method label uses helper translation only:

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

If I already have the translation on activerecord. it is not convenient to duplicate the code to perform the translation, so to solve this problem, just use the human_attribute_name, See the example below:

= City.human_attribute_name(:codigo_municipio)

In this way Rails uses the activerecord. instead of label helpers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.