I am using active record to create array.
users = User.all.to_a
now I want to later on find with in this array user id: 1
users.find(1)
but it is not giving result but returning everything. How can I search in this result array my selected user id. I can see users is a an array but with in array each record of User object.
If I do following
user.first
it return User object, but I want to search, how can I do it. I understand if I remove to_a then it will work but then it will create another sql query.
>Solution :
Since it is an array of objects, you should use find with block:
users.find { |user| user.id == 1 }