In Rails, I am getting an error when I try to evaluate whether the user has entered a brand for their computer:
if @user.computer.brand.empty?
NoMethodError (undefined method 'brand' for nil:NilClass):
If the user has not entered a computer, this will return an error that there is no method brand
on nil class
. What is the correct way to check that a user has both entered a computer
and a brand
for that computer?