ActiveRecord查询语法

时间:2013-02-07 08:53:18

标签: ruby-on-rails rails-activerecord

@past_topics = Topic.includes(:user, :event).where("event_id IS NOT NULL "cached_votes_up DESC").page(params[:page]).per(6)

这是我的代码。

如何在event.date < DateTime.now条件下将where添加到此代码?

1 个答案:

答案 0 :(得分:0)

只需追加它:)

@past_topics = ... # your code
@past_topics = @past_topics.where('events.date < ?', DateTime.now)