向Scope传递参数
向Scope传递参数
class Event < ActiveRecord::Base scope :recent, -> { |date| where(["created_at > ? ", date ]) } # 等同于 scope :recent, lambda{ |date| where(["created_at > ? ", date ]) } # 或 scope :recent, Proc.new{ |t| where(["created_at > ? ", t ]) } end Event.recent( Time.now - 7.days )