Search code examples
ruby-on-railsactiverecordruby-on-rails-3

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


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.


Solution

  • 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')