因此,我有一个允许用户注册试用期的应用,当试用期结束时,它们会转换为付费用户。现在,在管理员后端我有一个统计页面,但我在显示每日和每周注册时遇到问题。
我尝试过以下方法:
statistics_controller.rb
@trial_subscriptions = Subscription.where(state: 'trial')
@trial_today = @trial_subscriptions.where(created_at: [Date.today.beginning_of_day, Date.today.end_of_day])
@trial_week = @trial_subscriptions.where(created_at: [Date.today.beginning_of_week, Date.today.end_of_week])
和视图:
<div class="span4">
<h3>Free Trial</h3>
<table class='table table-bordered'>
<thead>
<tr>
<th></th>
<th>Sign-ups</th>
</tr>
</thead>
<tbody>
<tr>
<td>Today</td>
<td><%= @trial_today.count %></td>
</tr>
<tr>
<td>Week</td>
<td><%= @trial_week.count %></td>
</tr>
<tr>
<td>Total</td>
<td><%= @trial_subscriptions.count %></td>
</tr>
</tbody>
即使一位用户今天注册了,控制器代码也会返回零...
我做错了什么?
答案 0 :(得分:3)
@trial_subscriptions.where(:created_at => (Date.current.midnight)..(Date.current.next.midnight) )