您可以在 Rails 3 搜索中对日期进行大于比较吗? [英] Can you do greater than comparison on a date in a Rails 3 search?

查看:15
本文介绍了您可以在 Rails 3 搜索中对日期进行大于比较吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Rails 3 中有这个搜索:

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

但我需要 :date =>p[:date] 条件等价于 :date >p[:日期].我怎样才能做到这一点?感谢阅读.

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

推荐答案

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

或者您也可以将所有内容转换为 SQL 表示法

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

这篇关于您可以在 Rails 3 搜索中对日期进行大于比较吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆