1
2
3
4
|
class
WebSite < ActiveRecord::Base
scope
:valid
, where(
:status
=>
1
)
scope
:for_snatch
, valid.cts.order(
"id"
)
end
|
1
2
3
4
5
|
class
Event < ActiveRecord::Base
scope
:recent
, lambda{ |date| where([
"created_at > ? "
, date ]) }
#或scope :recent, Proc.new{ |t| where(["created_at > ? ", t ]) }
end
Event.recent(
Time
.now -
7
.days )
|
1
2
3
4
5
6
|
class
Event < ActiveRecord::Base
def
self
.recent(t=
Time
.now)
where([
"created_at > ? "
, t ])
end
end
Event.recent(
Time
.now -
7
.days )
|