This is probably one of the most basic questions out there but I still thought stackoverflow would be the best way for me to get the logic right.
My simple question is, how do you handle the database query if it does not return anything. Here is my code below;
@tokenSelected=Token.where(:tokenCode => "ABCDRRREF").first
And later on when I want to check if the @userSelected.userID is empty, it gives me the error;
<h1>
NoMethodError
in InitsController#create
</h1>
<pre>undefined method `empty?' for nil:NilClass</pre>
What can I do to prevent that
Instead of
empty?useblank?An object is blank if it’s false, empty, or a whitespace string. For example, “”, “ ”, nil, [], and {} are all blank.