I'm trying to find and record, is the record is nil, I don't want it on my array like this:
@kid << Kid.find_only_kid(k) unless nil
But when I get a nil, the record is inserted on the array.
This is the code of my find_only_kid method on my model:
def self.find_only_kid(kid)
Kid.where(_id: kid.to_s, parent: false, teacher: false).first rescue nil
end
Your code should be :
kid = Kid.find_only_kid(k)
@kid << kid unless kid.nil?
Note:
When a variable name is meant to hold collections, and it should be kids instead of kid. And the method name should be find_only_kids instead of find_only_kid.
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