-1

我创建了一个表来显示 ActiveRecord 查询结果。结果在表格中正确显示,但表格上方显示了其他结果。

在控制器中查询:

@plan = Plan.joins(:leads).
    where.not(leads: {plan_id: nil}).
    group('plan_name, plan_price_cents').
    select('plan_name, plan_price_cents*count(plan_id)/100 AS total_revenue')

看法:

<table class>
<thead>
<tr>
  <th>Plan Name</th>
  <th>Revenue</th>
</tr>
</thead>
<tbody>
<%= @plan.each do |plan| %>
  <tr>
    <td><%= plan.plan_name %></td>
    <td>$<%= plan.total_revenue %></td>
  </tr>
<% end %>
</tbody>

我希望只查看表格和结果。但我看到桌子和桌子[#<Plan id: nil, plan_name: "4 Lines">, #<Plan id: nil, plan_name: "T-Mobile One">, #<Plan id: nil, plan_name: "3 Lines">]上方。

4

1 回答 1

0

您需要更改此行

<%= @plan.each do |plan| %>

对此

<% @plan.each do |plan| %>

显示=值,因此它导致该循环将值输出到视图而不是循环遍历它。

于 2019-04-07T18:21:56.543 回答