开发者

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

开发者 https://www.devze.com 2023-03-17 22:04 出处:网络
Hi i have a problem when i\'m searching an array (@doweets is the array, array with Doweet objects, Doweet is like status...)

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
0

精彩评论

暂无评论...
验证码 换一张
取 消