【发布时间】:2012-01-14 11:59:41
【问题描述】:
我的 Rails (3.1) 控制器之一中有以下代码:
@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 天创建的呼叫计数,但仅适用于目的地与当前用户destination_id 值匹配的呼叫。
我尝试添加 :condition 但没有任何乐趣:
@count_day = Call.where(:destination => current_user.destination_id, :condition ['created_at > ?', 1.days.ago]).count
是否可以通过这种方式添加多个条件?如果有,怎么做?
【问题讨论】:
标签: ruby-on-rails-3 activerecord controller conditional-statements