Reputation: 3337
I'm writing a scope that should look for calls with a status of open and any call with a datetime greater than current time. I'm a bit fuzzy on the syntax, can someone help point me in the right direction.
Example that fails:
scope :scheduled_calls, where(:call_status => "open", :transfer_date > Time.now)
Upvotes: 1
Views: 1798
Reputation: 15089
Try this:
scope :scheduled_calls, where("call_status = 'open' and transfer_date > ?", Time.now)
Upvotes: 0
Reputation: 492
You need to use a lambda to evaluate the scope when it's called, as opposed to when the class is loaded.
scope :scheduled_calls, lambda { where(["call_status = ? and transfer_date > ?", "open", Time.now]) }
Upvotes: 6