I have the following code in one of my Rails (3.1) controllers:
@count = Call.where(:destination => current_user.destination_id).count
@count_day = Call.where('created_at > ?', 1.days.ago).count
@count_month = Call.where('created_at > ?', 30.days.ago).count
They are all working as expected, but I am trying to somehow merge two of them together so it shows the count of calls created in the last 1 day, but only for calls with a destination that matches the current users destination_id value.
I have tried to add :condition but with no joy:
@count_day = Call.where(:destination => current_user.destination_id, :condition ['created_at > ?', 1.days.ago]).count
Is it possible to add more than one condition in this way? If so, how?
Where creates a scope and scopes can be chained, so you can do