如何显示最近的注册? (为当天,周等...)

问题描述:

所以,我有一个应用程序,允许用户注册试用期,当试用期结束时,他们转换为付费用户。现在,在管理员后端我有一个统计页面,但我在显示每日和每周注册时遇到问题。如何显示最近的注册? (为当天,周等...)

我已经试过如下:

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> 

控制器代码返回零,即使一个用户今天签订了协议。 ..

我在做什么错?

@trial_subscriptions.where(:created_at => (Date.current.midnight)..(Date.current.next.midnight)) 
+0

嗯.. IRB(主):005:0> @ trial_subscription.where(created_at:(Date.current.midnight)..(Date.current.next.midnight)) NoMethodError:未定义的方法'在哪里'为零:NilClass – 2014-10-28 01:10:39

+0

啊很好,工作了一天..怎么样周周?谢谢 ! – 2014-10-28 01:14:44

+0

不要使用'irb',cd你的项目,并使用'rails c' – scottxu 2014-10-28 01:15:27