날짜별로 필터링하는 레일스에서 동적 범위를 사용하고 싶습니다. 나는이 같은 싶지 :scoped_by가 ActiveRecord (Rails)보다 많거나 적음
Foo.scoped_by_created_on(>the_future).scoped_by_created_on(<the_past).find(:all)
이것이 가능 또는 내가 작성 붙어 : conditions
해시를?
날짜별로 필터링하는 레일스에서 동적 범위를 사용하고 싶습니다. 나는이 같은 싶지 :scoped_by가 ActiveRecord (Rails)보다 많거나 적음
Foo.scoped_by_created_on(>the_future).scoped_by_created_on(<the_past).find(:all)
이것이 가능 또는 내가 작성 붙어 : conditions
해시를?
scoped_by
으로는이 작업을 수행 할 수 없지만 자신의 범위를 지정할 수는 있습니다.
named_scope :created_on_before, lambda { |time| { :conditions => ["created_on < ?", time] } }
named_scope :created_on_after, lambda { |time| { :conditions => ["created_on > ?", time] } }
또는 Searchlogic을 확인하십시오. 여기에는 이름이 지정된 범위가 나와 있습니다.
Foo.created_on_greater_than(the_future).created_on_less_than(the_past)
내가 (다른 사람의 사이에) 당신은 과거와 미래의 방법을 모두 제공 by_star라는 플러그인을 가지고 그래서 당신은 할 수 있습니다 :
@foos = Foo.past(some_time) do
Foo.future(some_other_time)
end
그냥 메모를 레일 (3)과 같은, 더 간결 그 접근이 가능합니다 :
named_scope :created_between, -> (past,future) { where(created_on: past..future) }
사용법 :
Foo.created_between(the_past,the_future)
감사합니다. 아프다. – user94154