use*_*621 3 ruby helper where conditional-statements ruby-on-rails-3
我有以下辅助方法:
def orders_chart_series(orders, start_time)
orders_by_day = orders.where(:created_at => start_time.to_date..Date.today).
group("date(created_at)").
select("created_at, count(id) as total_price")
(start_time.to_date..Date.today).map do |date|
order = orders_by_day.detect { |order| order.created_at.to_date == date }
order && order.total_price.to_f || 0
end.inspect
end
Run Code Online (Sandbox Code Playgroud)
我仍然收到此线程名称中的错误。我试图打印订单参数的内容,我得到了这个:
#<User:0x00000104c69b98>
Run Code Online (Sandbox Code Playgroud)
这个问题是什么意思?我尝试搜索此问题的解决方案,但我仍然知道如何解决它。我也尝试替换命令where for conditions,但还是一样。
对于这个问题的每一个帮助,我将非常感激,谢谢。
你试图调用where一个User-instance,而不是在User-class(where是一个类的方法)。你可以orders.where改为orders.class.where.
(在名为 orders 的变量中有一个 User 实例也有点令人困惑,但这可能只是我。)