【发布时间】:2016-04-08 03:02:20
【问题描述】:
我有一个方法如下...
def self.get(code)
where(code: normalize_code(code)).
where('coupon_count > 0').
where('expires_at > Time.now OR expires_at IS NULL').
take
end
我在“take”行上不断收到错误“参数数量错误(0 代表 1)”。我使用的是 rails 4.0.1 是导致问题还是我遗漏了什么?
编辑查看 4.0.1 http://rails.documentation.codyrobbins.com/4.0.10/classes/ActiveRecord/FinderMethods.html#method-i-take 的文档
我将方法更新为
def self.get(code)
where(code: normalize_code(code)).
where('coupon_count > 0').
where('expires_at > Time.now OR expires_at IS NULL').
take(1)
end
现在我得到了错误
SyntaxError: Unexpected identifier (16722)
错误在“take”行
-更新-
我的错误在于 coupon_count 的 where 方法。它不在 take 方法中。在接受优惠券之前,我必须弄清楚它不会检查coupon_count 字段的内容。
【问题讨论】:
-
你能给出确切的堆栈跟踪吗?
标签: ruby-on-rails mongoid take