How to average the last table in Rails

Asked

Viewed 52 times

1

personal I have the following doubt that my code it increments for whenever it has an evaluation it shows, but, the media always gets after as if it were a note

<% @registration.matrix.blocks.each do |block| %>
    <h5>Bloco: <%= block.description %></h5>
    <div class="table-responsive">
        <table class="table table-sm table-striped table-bordered shadow-sm">
            <thead class="thead-dark">
            <tr>
                <th>Disciplina</th>
                <th>Faltas Atribuidas</th>
                <th>Prova 1</th>
                <th>Prova 2</th>
                <th>Prova 3</th>
                <th>Prova 4</th>
                <th>Prova 5</th>
                <th>Prova 6</th>
                <th>Prova 7</th>
                <th>Prova 8</th>
                <th>Prova Final</th>
                <th>Média</th>
            </tr>
        </thead>
        <tbody>
            <% block.disciplines.distinct.each do |discipline| %>

            <tr>
                <td><%= discipline.name %></td>
                <td>
                    <%= number_of_absences(current_user, discipline) %>
                </td>
                <% discipline.evaluations.each do |evaluation| %>
                    <td><%= Evaluate.get_evaluate(current_user.id, evaluation.id).present? ? Evaluate.get_evaluate(current_user.id, evaluation.id).note : '0,0' %></td>
                <% end %>
                <td><%= get_media(current_user, discipline) %></td>
            </tr>
            <% end %>
        </tbody>
    </table>
<% end %>
</div>

So I’d like to know how I do to fix the error, for example I put the note 10, it divides by 8 as I programmed, but the average is 10/8 since 10 was the only note that assigns, it is 1.25 but the media is on the side and not at the end, how do I put at the end in the table "average"

Conforme é visto na imagem seguinte

2 answers

0

The average result is not showing up at the end because you need that amount of <th></th> be the same amount of <td></td>.

In your example you 12 <th> tags and only 3 <td>.

You should always leave the same amount and in your case you will need as you put the notes (proof -> 1,2,3,4,5,6,7,8, final)

      <table class="table table-sm table-striped table-bordered shadow-sm">
                <thead class="thead-dark">
                <tr>
                    <th>Disciplina</th>
                    <th>Faltas Atribuidas</th>
                    <th>Prova 1</th>
                    <th>Prova 2</th>
                    <th>Prova 3</th>
                    <th>Prova 4</th>
                    <th>Prova 5</th>
                    <th>Prova 6</th>
                    <th>Prova 7</th>
                    <th>Prova 8</th>
                    <th>Prova Final</th>
                    <th>Média</th>
                </tr>
            </thead>
            <tbody>
                <% block.disciplines.distinct.each do |discipline| %>

                <tr>
                    <td><%= discipline.name %></td>
                    <td>
                        <%= number_of_absences(current_user, discipline) %>
                    </td>
                    <% discipline.evaluations.each do |evaluation| %>
                        <td><%= Evaluate.get_evaluate(current_user.id, evaluation.id).present? ? Evaluate.get_evaluate(current_user.id, evaluation.id).note : '0,0' %></td>
                    <% end %>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td><%= get_media(current_user, discipline) %></td>
                </tr>
                <% end %>
            </tbody>
        </table>
  • face until "worked" happens that when I assign the second note, ai jumps and Buga kk

0

Use the "times" to make a loop of the times you have to repeat the , the difference being between 8 and the size of the notes.

<% discipline.evaluations.each do |evaluation| %>
<td><%= Evaluate.get_evaluate(current_user.id, evaluation.id).present? ? Evaluate.get_evaluate(current_user.id, evaluation.id).note : '0,0' %></td>
<% end %>
<% (8 - discipline.evaluations.length).times do %>
  <td></td>
<% end %>

I just don’t know if it’s "pretty".

Browser other questions tagged

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