gal
gal

Reputation: 302

how to search from an array? (i have a problem when i'm searching an array)

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 array? 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

Upvotes: 0

Views: 53

Answers (2)

Ian Yang
Ian Yang

Reputation: 1406

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:

Upvotes: 0

Wukerplank
Wukerplank

Reputation: 4176

Not tested, but it should look a bit like this:

doweets = @doweets.select{|d| d.date>=time1 && d.date<=time2}

Upvotes: 2

Related Questions