Hi i have a problem when i'm searching an array (@doweets is the array, array with Doweet objects, Doweet is like status...)
how can i do the same search like here:
doweets = Doweet.where(:date => time1..time2)
on variable of ar开发者_高级运维ray? when i write like this i get an error:
doweets = @doweets.where(:date => time1..time2)
what to do, to do it with select? how can i do it?
thanks guys,
gal
Not tested, but it should look a bit like this:
doweets = @doweets.select{|d| d.date>=time1 && d.date<=time2}
where
is a method of Relation
. Don't use all
to return all results as Array
. You can add finder methods as chain, and the query is executed when results are required, i.e., each
, first
or all
are invoked. For Array
, you should use find_all
to search.
FYI:
- ActiveRecord Query Interface
- Module Enumerable
精彩评论