Ruby on rails 3 Rails 3中的范围评估时间

Ruby on rails 3 Rails 3中的范围评估时间,ruby-on-rails-3,datetime,scope,Ruby On Rails 3,Datetime,Scope,我正在编写一个作用域,它应该查找状态为open的调用以及datetime大于当前时间的任何调用。我的语法有点模糊,有人能帮我指出正确的方向吗 失败的示例: scope :scheduled_calls, where(:call_status => "open", :transfer_date > Time.now) 在调用作用域时,需要使用lambda来计算作用域,而不是在加载类时 scope :scheduled_calls, lambda { where(["call_stat

我正在编写一个作用域,它应该查找状态为open的调用以及datetime大于当前时间的任何调用。我的语法有点模糊,有人能帮我指出正确的方向吗

失败的示例:

scope :scheduled_calls, where(:call_status => "open", :transfer_date > Time.now)

在调用作用域时,需要使用lambda来计算作用域,而不是在加载类时

scope :scheduled_calls, lambda { where(["call_status = ? and transfer_date > ?", "open", Time.now]) }

在调用作用域时,需要使用lambda来计算作用域,而不是在加载类时

scope :scheduled_calls, lambda { where(["call_status = ? and transfer_date > ?", "open", Time.now]) }
试试这个:

scope :scheduled_calls, where("call_status = 'open' and transfer_date > ?", Time.now)
试试这个:

scope :scheduled_calls, where("call_status = 'open' and transfer_date > ?", Time.now)
此处应使用lambda以避免时间缓存。此处应使用nowlambda以避免时间缓存。现在