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

后端 未结 4 398
天命终不由人
天命终不由人 2020-12-04 08:52

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 A         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 09:30

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

提交回复
热议问题