gpt4 book ai didi

ruby - Rails 3 - # 的未定义方法 `where'

转载 作者:太空宇宙 更新时间:2023-11-03 17:58:54 25 4
gpt4 key购买 nike

我有以下辅助方法:

  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

我仍然收到此线程名称中的错误。我尝试打印 orders 参数的内容,我得到了这个:

#<User:0x00000104c69b98>

这个问题是什么意思?我试图寻找这个问题的解决方案,但我仍然知道如何解决它。我还尝试将命令 where 替换为 conditions,但还是一样。

我将非常感谢有关此问题的所有帮助,谢谢。

最佳答案

您正在尝试在 User 实例上调用 where,而不是在 User 类(where 是一个类方法)。您可以将 orders.where 更改为 orders.class.where

(在名为 orders 的变量中有一个 User 实例也有点令人困惑,但这可能只是我。)

关于ruby - Rails 3 - #<User :0x00000104c69b98> 的未定义方法 `where',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8490846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com