Ruby on rails Rails 3.2型号范围日期小于_

Ruby on rails Rails 3.2型号范围日期小于_,ruby-on-rails,ruby,ruby-on-rails-3.1,ruby-on-rails-3.2,Ruby On Rails,Ruby,Ruby On Rails 3.1,Ruby On Rails 3.2,我试图创建一个作用域,通过我的deadline属性在我的模型中查找数据集,例如,少于一年,少于六个月 class Goal < ActiveRecord::Base attr_accessible :category, :title, :detail, :deadline, :achieve #need help solving this scope :less_than_a_year, where() end class目标

我试图创建一个作用域,通过我的deadline属性在我的模型中查找数据集,例如,少于一年,少于六个月

class Goal < ActiveRecord::Base
  attr_accessible :category, :title, :detail, :deadline, :achieve

  #need help solving this
  scope :less_than_a_year, where()
end
class目标
因此,它将执行,目标。少于一年,并提供少于一年的数据列表。
谢谢。

我很确定这是特定于数据库的,但它应该适用于大多数情况

class Goal < ActiveRecord::Base
  scope :less_than_a_year, lambda{ where("deadline < ?", 1.year.from_now) }
end
class目标
这假设截止日期是
日期
日期时间

编辑:根据

范围:小于一年,lambda{where(“截止日期<?”,1.year.from\u now)}
课程目标
您忘记了密码?而且拼错了lambda
scope :less_than_a_year, lambda { where("deadline < ?", 1.year.from_now ) }
class Goal < ActiveRecord::Base

 #need help solving this
 scope :less_than_a_year, labmda { where("deadline < ", 1.year.ago)}

end