The answer is that @friendpicks is an array and that you are getting
the object id of the array, not the model ids of the contents of the @friendpicks array.
The answer is that @friendpicks is an array and that you are getting
the object id of the array, not the model ids of the contents of the @friendpicks array.
@friendpicks = @u.friends.collect do |friend|
friend.products.sort_by do |product|
product.id
end.reverse.first(10)
end
So, if I’ve reinterpreted this right, you’re getting a list of lists
of 10 products each, sorted by their id, then reversed.
So to access each of the lists you want @friendpicks.each. Then to
access each of the picks lists you want @friendpicks.each{|pick|
pick.each} Which will ultimately get you:
@friendpicks.each do |picks|
picks.each do |pick|
pick.id
end
end
Now, if you’ve got your console open, you can check the class of each
of the objects by using the class method, and if you want to inspect
them, try either p or inspect.