My setup: Rails 3.0.9, Ruby 1.9.2
Let’s say I did a find all on a model
@projects = Project.all
Now I would like find an individual record within the resultset just returned without having to make it another SQL call. This line of code triggers a new SQL call, I’ll like to avoid it if possible, figures there should be a way to grab the record from the resultset
@projects.find(1)
@projectsis just an array of Project objects now you can simply use any ruby operator that operates on arrays to find the object you want.For example:
is the same as your example.
You could also use something like:
if you knew you could match multiple items.