price.nil? should not return true if the value of price is 0. nil is an object that is the anti-matter of objects. It is something that isn’t really there. It’s not 0, it’s not a blank string, they would be something. No, this is nothing. ( does anyone have a racing snail? ) The nil? method, available on all objects, will only return true if the return value is nil ( ie nothing )
So the logic of the code says
add an error to the price field unless price is nil (nothing) or if price is greater than 0.
This means that price can be nil (or blank or however you want to think about it but blank is another method in rails) or it can be positive. Any other value and the error gets added to the price attribute.
Hope that helps a bit.