There was a stage when a code like this was written in our Rails app
user = User.where(name: "John") if user something..... end
The question is will the something get executed only if there is a user named John in database, or it gets executed every time. Sadly it gets executed all the time.
So why it happens. Try this in your irb
>> puts "A" if  A => nil >> puts "A" unless .empty? => nil >> puts "A" if .first => nil
So if you see, when we pass an empty array to a condition, its always true!!!
You must remember it like this, even though a rack or shelf is empty, the shelf itself is a object, so its present, its the truth. In the next two examples, I have shown how to check and make things false if array is empty. So happy coding!
I think you can avoid all the array stuff hassel if you use the following type of code in Rails
user = User.find_by(name: "John") if user something..... end
OR, this one
user = User.where(name: "John").first if user something..... end
So. Enjoy life. Happy Coding.