cgf
cgf

Reputation: 3509

Ruby's nil? function not working

I am using Ruby 1.9.3.

This is what is happening in the console:

1.9.3-p392 :028 > p = Product.find(1)
  Product Load (0.4ms)  SELECT `products`.* FROM `products` WHERE `products`.`id` = 1 LIMIT 1
 => #<Product id: 1, name: "Product 4", image: nil, available: true> 
1.9.3-p392 :029 > p.image
 =>  
1.9.3-p392 :030 > p.image.nil?
 => false

When the product is returned, the image is obviously nil, but when I try and get the value (p.image) it does not show anything.

Why is the p.image.nil? command not returning true?

Upvotes: 2

Views: 406

Answers (1)

OMY
OMY

Reputation: 412

Use .blank? it'll return true if the attribute is nil or empty

Upvotes: 6

Related Questions