<ActiveRecord::QueryMethods::WhereChain 在工作范围内出错

Ste*_*fat 0 ruby-on-rails

我已经成功运行了一段时间的代码,但它刚刚开始抛出错误 - 我们已经改变了数据进入数据库的方式,但相信它更有可能是一个编程问题,或者我已经改变了它错误,但看不到哪里。

该问题似乎是由范围引起的,我们正在运行 Rails 4.2.2

完整的错误是

undefined method `call' for 
 ActiveRecord::QueryMethods::WhereChain:0x007feb8f5c49f0> Did you mean? caller

app/controllers/orders_controller.rb:158:in `weekly_sales_report'
Run Code Online (Sandbox Code Playgroud)

在我的 orders_controller 第 158 行

@sales_this_week_bysales = Order.select("COUNT(order_id) AS nosales, AVG(net_amount) AS avgsale,SUM(sale_cost) AS sale_cost, SUM(net_amount) AS weeklysalestotal, owner_id AS salesman").sales.where.(date_of_sale: (@startdate .. @enddate)).with_salesman.group(:owner_id)
Run Code Online (Sandbox Code Playgroud)

在我的 orders.rb 模型中,我使用了以下范围

scope :with_salesman, -> { joins(:pipe_records).where(pipe_records: {pipe_part_id: 1}).where.not(pipe_records: {owner_id: nil}) }

scope :sales, -> {where ("orders.order_ref <>'' and date_of_sale IS NOT NULL ")}
Run Code Online (Sandbox Code Playgroud)

我将范围重新写入下面,但仍然出现相同的错误

scope :with_salesman, -> { joins(" INNER JOIN pipe_records ON pipe_records.order_id = orders.id WHERE pipe_records.pipe_part_id =1 AND pipe_records.owner_id <>'' ") }
Run Code Online (Sandbox Code Playgroud)

我还从 158 上的 sales.where 中删除了 WHERE startdate 标准,它返回了一个不同的错误,但似乎范围不再正确传递或由于记录错误而返回错误?

我现在不确定发生了什么,我回到我的遥控器并获取了几天前的代码副本,这也引发了同样的错误,但它工作正常。我们最近通过一种新形式放入了许多新记录,该形式绕过并更改了可能应归咎于日期的日期。我将不胜感激任何建议或新鲜的眼睛。

eng*_*nky 6

只需删除where和括号之间的句点。

where.(date_of_sale: (@startdate..@enddate))
Run Code Online (Sandbox Code Playgroud)

ruby

receiver.()
Run Code Online (Sandbox Code Playgroud)

receiver.call()您收到的错误的简写