Conditional logic when dealing with nil

I had a piece of code in an rjs file that checked to see if a variable

if @product
… do something here …

that worked fine, but then I also need to check and see if a column is
empty or nil, so i changed it to this:

if @product || !@product.price.blank?
… do something here …

this always gives me “You have a nil object when you didn’t expect
it!” errors

is there a better way of doing this without nesting if statements
inside eachother?

Try this:
if @product && @product.price.blank?

Do something here


In the code below, if @product is nil, the first condition is false so
the second condition is evaluated. @product.price will fail when
@product is nil.