When you call find_by , it gets into the database.
A relationship object is used to lazily load db results.
Once they are loaded to call all , you can search the resulting array.
If you want to look at the results already recorded in your ruby โโprocess, you have to look into the array using find or detect (which do the same). I usually use detect , so it is clear that it does not get into the database:
@blogs.detect { |b| b.id == 1 }
http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-detect
Andrew Kuklewicz
source share