Can you do greater than comparison on a date in a Rails 3 search?

ben picture ben · Nov 19, 2010 · Viewed 118.6k times · Source

I have this search in Rails 3:

Note.where(:user_id => current_user.id, :notetype => p[:note_type], :date => p[:date]).order('date ASC, created_at ASC')

But I need the :date => p[:date] condition to be equivilent to :date > p[:date]. How can I do this? Thanks for reading.

Answer

Simone Carletti picture Simone Carletti · Nov 19, 2010
Note.
  where(:user_id => current_user.id, :notetype => p[:note_type]).
  where("date > ?", p[:date]).
  order('date ASC, created_at ASC')

or you can also convert everything into the SQL notation

Note.
  where("user_id = ? AND notetype = ? AND date > ?", current_user.id, p[:note_type], p[:date]).
  order('date ASC, created_at ASC')