按日,周,月显示销售报表

按日,周,月显示销售报表

问题描述:

如何生成日销售报表?以下是我的代码报告控制器和意见。当我打开dailyreport页面时,它给出错误“未定义的方法,每个”为零:NilClass“ 这是我的报告控制器。按日,周,月显示销售报表

class ReportController < ApplicationController 
    def daily 
    @sale = Sale.where("created_at >= ?", Time.zone.now.beginning_of_day) 
    end 

    def weekly 

    end 

    def monthly 

    end 

    def topselling 

    end 
end 

这是我的看法

<table class="table table-striped"> 
    <thead> 
    <tr> 
     <th>Sale ID</th> 
     <th>Name</th> 
     <th>Created Date</th> 
     <th>Total</th> 
     <th colspan="2"></th> 
    </tr> 
    </thead> 

    <tbody> 
    <% @sales.each do |sale| %> 
     <tr> 
     <td>#<%= sale.id %></td> 
     <td><%= sale.name %></td> 
     <td><%= sale.created_at %></td> 
     <td>Rs.<%= sale.total %></td> 
     </tr> 
    <% end %> 
    </tbody> 
</table> 
+1

您已经定义了'@ sale',但使用的是'@ sales'。 – Pavan

+0

非常感谢..这是一个愚蠢的错误。 –

更改@sale变量@sales

@sales = Sale.where("created_at >= ?", Time.zone.now.beginning_of_day) 
+0

非常感谢 –