0

This is how I am showing the records of orders:

           <% @orders.uniq.each do |order| %>
          <% @count += 1 %>
          <tr class="even border_text">
            <td width="30"><strong><%= @count %></strong></td>
            <td width="180"><strong><%= order.first_name %> <%= order.last_name %></strong></td>
            <td width="180"><strong>Rs.<%= order.amount %></strong></td>
            <td width="180"><strong><%= order.status %></strong></td>
            <td><strong><%= order.created_at %></strong></td>
            <td width="70px" align="center"><%= link_to edit, edit_admins_order_path(order.id) %>
          </tr>
      <% end %>

And controller:

         @orders = Order.joins(:user).joins(:order_statuses).select("orders.id,users.first_name,users.last_name,orders.amount,orders.description,orders.created_at,order_statuses.status, max(order_statuses.created_at)").group("orders.id,users.first_name,users.last_name,orders.amount,orders.description,orders.created_at,order_statuses.status").page(params[:page]).per_page(10)

Problem is it is showing duplicate values if the status is changed or updated. How do I show unique values by orders.id

4

2 回答 2

1

应该做的伎俩:

<% @orders.uniq(&:id).each do |order| %>
于 2013-07-31T10:24:24.277 回答
0

试试这个:

<% @orders.uniq{|x| x.id}.each do |order| %>

希望它会有所帮助。谢谢

于 2013-07-31T10:21:05.540 回答