I want to use a dynamic scope in Rails where I filter by date. I want to do something like this:
Foo.scoped_by_created_on(>the_future).scoped_by_created_on(<the_past).find(:all)
Is this possible or am I stuck writing a :conditions
hash?
I want to use a dynamic scope in Rails where I filter by date. I want to do something like this:
Foo.scoped_by_created_on(>the_future).scoped_by_created_on(<the_past).find(:all)
Is this possible or am I stuck writing a :conditions
hash?
You can't do this with scoped_by
however you can make your own scopes for this.
named_scope :created_on_before, lambda { |time| { :conditions => ["created_on < ?", time] } }
named_scope :created_on_after, lambda { |time| { :conditions => ["created_on > ?", time] } }
Alternatively check out Searchlogic which offers named scopes for this.
Foo.created_on_greater_than(the_future).created_on_less_than(the_past)