So, I want to search in fetched records:
p = Product.added_today # Get records by scope
# wants something like
p.search(:name => 'Clocks')
Is there easy (rails way) to do it (gem or something)?
So, I want to search in fetched records:
p = Product.added_today # Get records by scope
# wants something like
p.search(:name => 'Clocks')
Is there easy (rails way) to do it (gem or something)?
one way would be using ruby's find_all -
q = p.find_all{ |e| e.name == 'Clocks' }
as this this code uses brute force ruby array search, performance isn't great. if you expect p to contain more than a few tens of elements, using database queries would be better, performance wise.
You can use the following Rails features to mimic that kind of search.
Try building on your scope:
Product.added_today.find(:all, :conditions => {:name => 'Clock'})
Try this:
pa = Product.added_today
pa.select{|p| p.name == "Clocks"}