【发布时间】:2012-11-18 09:47:56
【问题描述】:
嘿,我的查找条件有点长,我想加长一点。
到目前为止
:conditions => ["name LIKE ? OR description LIKE ?", "%#{params[:search_keyword]}%",
"%#{params[:search_keyword]}%"]
如果属性 :name 或 :description 类似于文本框中的参数,它在哪里搜索模型。现在我还想添加以确保找到的条目是最新的。我已经有了
:conditions => ["start_date between ? and ? ", Date.today, @yearstime ]
@yearstime 是 @yearstime = Date.today + 365.days,所以基本上模型中从当前日期到一年后的所有内容
我想结合这两个条件,但不确定语法。我试着把它们放在一起。
:conditions => ["name LIKE ? OR description LIKE ? AND start_date between ? and ?",
"%#{params[:search_keyword]}%", "%#{params[:search_keyword]}%", Date.today, @yearstime ]
但它仍然没有计算日期参数....知道我做错了什么吗?
【问题讨论】:
标签: ruby-on-rails find conditional-statements