我有一个像这样的控制器:
products_controller.rb
def index
@products = Product..where('order_date BETWEEN ? AND ?', DateTime.now.beginning_of_day, DateTime.now.end_of_day).all
#[id, order_date, name, category]
end
index.html.erb
<% @products.each do |product| %>
<thead>
<th>
<%= product.category %>
</th>
</thead>
<tbody>
<tr>
<%= product.name %>
</tr>
</tbody>
# This code loop through each product to display its product category and the product name.
如何定义条件,以便product.category
等于之前的product.category
,然后将product.name
追加到<tbody>
?