Afternoon,
Lets say I have gather a random selection of users:
User.find(:all, :limit => 10, :order => "rand()")
Now from these results, I want to see if the user with the ID of 3 was included in the results, what would be the best way of finding this out?
I thought about Array.include? but that seems to be a dead end for me.
Thanks
JP
users = User.find(:all, :limit => 10, :order => "rand()")
users.any? {|u| u.id == 3}
assert random_users.include?(User.find 3), "Not found!"
Active record objects are considered equal if they have equal ids. Array#include? respects the objects defined equality via the ==
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With