无法为控制器添加少于检查条件

时间:2015-04-27 03:20:36

标签: ruby-on-rails

我有以下内容在控制器中很好用:

@packers = Packer.find(:all, :conditions => { :p_team => "t" ,  :p_cspa_date => DateTime.now }, :order => "p_name")

但是我无法完成以下工作:

@packers = Packer.find(:all, :conditions => { :p_team => "t" ,  :p_cspa_date < ?, DateTime.now }, :order => "p_name")

基本上

@packers = Packer.find(:all, :conditions => { :p_team => "t" ,  :p_cspa_date LESS THAN DateTime.now }, :order => "p_name")

控制台的架构如下:

irb(main):064:0> Packer.last.p_cspa_date 
Packer Load (0.3ms)  SELECT "packers".* FROM "packers" ORDER BY "packers"."id" DESC LIMIT 1
=> Fri, 22 Mar 2013
irb(main):065:0> Packer.last.p_team
Packer Load (0.3ms)  SELECT "packers".* FROM "packers" ORDER BY "packers"."id" DESC LIMIT 1
=> true
irb(main):066:0> 

1 个答案:

答案 0 :(得分:0)

尝试将"p_cspa_date < ?"替换为@packers = Packer.where("p_team = 't' AND p_cspa_date < ?", DateTime.now).order(:p_name) 或将整个内容替换为:

{{1}}