small medium large xlarge

Generic-user-small
06 Mar 2015, 20:43
ives6395 (1 post)

I’m having trouble with correcting the error message on pp. 225-226. In App/Views/Orders/_Form.html.erb I got an error message for the line:

<li><%= raw msg %></li>

orders/_form looks like this:

<%= form_for(@order) do |f| %>
  <% if @order.errors.any? %>
    <div id="error_explanation">
      <h2><%=raw t('errors.template.header', count: @order.errors.count,
        model: t('activerecord.models.order')) %>.</h2>
    <p><%= t('errors.template.body') %></p>

    <ul>
    <% @order.errors.full_messages.each do |msg| %>
      <li><%=raw msg %></li>
    <% end %>
    </ul>
  </div>
  <% end %>
<!--... -->

Then when I refreshed the /orders webpage continued to get the error messages in English with translation missing. Not sure what I am doing wrong!

Generic-user-small
17 Sep 2015, 13:13
David Svedberg (1 post)

Hi, I was stuck on the same issue, got around it by fully qualifying the lookup string for t by adding activerecord in front or it i.e.:

<h2><%= raw t('activerecord.errors.template.header',
                    count: @order.errors.count,
                    model: t('activerecord.models.order')) %>.</h2>
<p><%= t('activerecord.errors.template.body') %></p>

also in the yml translation file they keep repeating some levels e.g. “errors” multiple times, to get it to work I had to remove all those repetitions:

activerecord:
    errors:
      messages:
        inclusion: "måste väljas från listan"
        blank: "måste fyllas i"
      template:
        body: "Följande fält är felaktigt ifyllda"
        header:
          one: "Ett fel förhindrar denna %{model} från att utföras"
          other: "%{count} fel förhindrar denna %{model} från att utföras"
    models:
      order: "beställning"
    attributes:
      order:
        address: "Adress"
        name: "Namn"
        email: "E-mail"
        pay_type: "Betalningsalternativ"
You must be logged in to comment