添加多个字符串控制器查找条件? [英] Adding more than one string to a controller find condition?
本文介绍了添加多个字符串控制器查找条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code在我的Rails一(3.1)控制器:
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
他们都按预期工作,但我试图以某种方式合并两个人在一起,因此它显示在最近1天中创建的呼叫数,但仅限于与目标相匹配的当前用户的目标ID值调用。
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
Call.where(:destination =>current_user.id).where("created_at > ?", 1.day.ago).count
这篇关于添加多个字符串控制器查找条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文