在没有SQL的情况下使用Rails "where"方法获取日期之前/之后的记录的语法是什么?



没有SQL的语法是什么?

Subscription.where('end_date > ?', Date.today)

我已经尝试过这个,但它显然是不正确的:

Subscription.where(:end_date > Date.today)

(我们正在使用导轨 3)谢谢!

通过使用 Arel:

Subscription.where(Subscription.arel_table[:end_date].gt(Date.today)).all

或者使用宝石尖叫:

Subscription.where(end_date.gt => Date.today).all

最新更新