在 tasks_controller 中,我定义了:
def index
@tasks = Task.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tasks }
end
end
我的表中有三个参数:名称、任务、完成。
现在,我想制作:
<table>
<tr>
<th>Name</th>
<th>num of tasks</th>
<th>num tasks left</th>
</tr>
<% @tasks.group_by(&:name).each do |name, tasks| %>
<tr>
<td><%= name %></td>
<td><%= tasks.size %></td>
<td> here I want to produce the number of tasks left </td>
</tr>
<% end %>
</table>
我怎样才能得到剩余的任务数?我认为它应该是这样的:
<% @tasks.group_by(&:name).each do |name, tasks| %>
<tr>
<td><%= name %></td>
<td><%= tasks.size %></td>
<% @tasks.group_by(name, :done => "yes").each do |name, tasks| %>
<td><%= tasks.size %></td>
<% end %>
</tr>
<% end %>