【发布时间】:2020-04-12 05:30:48
【问题描述】:
您好,我是 ruby on rails 的新手。我正在尝试构建一个包含日期字段的页面,在选择特定日期后,我想生成一个显示此日期选择报告的表格。
控制器/reports_controller.rb
class ReportsController < ApplicationController
def index
end
def test
@chosen_date = params[:report_date]
@incoming_messages = Message.where("inbound = 't' and created_at like '" + @chosen_date + "%'").count
@total_chats = Message.where("created_at like '" + @chosen_date + "%'").distinct.count(:phone_number)
@enrollment_by_andi = Enrollment.where("created_at like '" + @chosen_date + "%' and created_by = 'ANDI'").count
@enrollment_by_agent = Enrollment.where("created_at like '" + @chosen_date + "%' and created_by <> 'ANDI'").count
@sent_by_andi = Message.where("created_by = 'ANDI' and created_at like '" + @chosen_date + "%'").count
@sent_by_agents = Message.where("inbound = 'f' and created_by <> 'ANDI' and created_at like '" + @chosen_date + "%'").count
@unread_messages = Message.where("created_at like '" + @chosen_date + "%' and is_read = 'f'").distinct.count(:phone_number)
end
end
视图/报告/index.html.erb
<h1>Reports</h1>
<%= form_tag(reports_test_path,:method => "post") do %>
<%= label_tag(:report_date,"Choose a Date") %>
<%= date_field_tag(:report_date)%>
<%= button_tag "Submit"%>
<% end %>
我要生成的表:
<table>
<th>
<td>Incoming Messages</td>
<td>Total Chats</td>
<td>Enrollment By Andi</td>
<td>Enrollment By Agent</td>
<td>Sent By Andi</td>
<td>Sent By Agents</td>
<td>Unread Messages</td>
</th>
<tr>
<td><%= @incoming_messages %></td>
<td><%= @total_chats %></td>
<td><%= @enrollment_by_andi %></td>
<td><%= @enrollment_by_agent %></td>
<td><%= @sent_by_andi %></td>
<td><%= @sent_by_agents %></td>
<td><%= @unread_messages %></td>
</tr>
</table>
以下是页面图片:
当我按下按钮时,任何人都可以帮助我找到在日期字段下生成表格的方法吗?
【问题讨论】:
标签: html ruby-on-rails model-view-controller ruby-on-rails-5