Access to translations of model attributes when displaying errors

I successfully created my.yml to localize the names of my models, Example:

      attributes:
       vendor:
        name: שם ספק
        counter_number: מספר חשבונית
        phone: טלפון
        address: כתובת

Now, displaying labels in forms using simple_form f.input, it displays it correctly, the translated value of each attribute.

the problem is displaying errors after validation using

<% @vendor.errors.each do |attribute, error| %>

| attribute | for the error "counter_number", for example, displays: "counter_number". but not translated into a locale file [which, as I mentioned earlier, is configured and loaded successfully]. I added errors to ul.errors, as shown in this screenshot: enter image description here

Thanks in advance.

+4
source share
2

- :

@vendor.errors.messages do |attribute, errors|
  translated_attribute = Vendor.human_attribute_name(attribute)
  errors = errors.join(", ")
end

User:

enter image description here

+1

.

<% @vendor.errors.each do |attribute, error| %>
  <strong><%= t("activerecord.attributes.#{@vendor.class.to_s.underscore}.#{attribute}") %>:</strong>
  <%= error.messages.to_sentence %>
<% end %>

, , .

+1

All Articles