簡體   English   中英

拋出錯誤的參數數量錯誤

[英]Throws wrong number of arguments error

Rails活動記錄將引發以下錯誤。

 irb(main):030:0* Subscription.where(valid_until: nil).where.not(activated_on: nil)
    ArgumentError: wrong number of arguments (given 0, expected 1+)

Valid_until共有5個nil條目

irb(main):032:0> Subscription.where(valid_until: nil).count
2017-05-02 19:03:43.867 [MEH]  (0.6ms)  SELECT COUNT(*) FROM "pti_subscriptions" WHERE "pti_subscriptions"."valid_until" IS NULL
=> 5

問題出在哪里。 有任何想法嗎?

在Rails 4中引入了where.not。 您正在使用Rails 3.2.13,因此必須執行以下操作:

 Subscription.where('valid_until IS NULL and activated_on IS NOT NULL')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM