<活动记录::查询方法::工作范围上的何处链错误



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

这个问题似乎是由一个范围引起的,我们正在运行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'

在我的订单中_控制器线路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)

在我的订单.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 ")}

我把范围重新写到下面,但仍然得到了相同的错误

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 <>'' ") }

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

我现在不确定发生了什么,我回到遥控器上,从几天前的代码中复制了一份,这也引发了同样的错误,但它工作正常。最近,我们通过一种新的形式加入了很多新的记录,这种形式绕过并改变了可能是罪魁祸首的日期。如果有任何建议或新鲜的眼光,我将不胜感激。

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

where.(date_of_sale: (@startdate..@enddate))

ruby

receiver.()

receiver.call()人手不足,因此您收到时出现错误

您可能希望在where:之后删除该周期

where.(date_of_sale: (@startdate .. @enddate))

相关内容

最新更新