I am reading the book 'agile web development with rails' and I am at the part where they are going through validations, listed below:
class Product < ActiveRecord::Base
validates :description, :title, :image_url, presence: true
validates :price, numericality: {greater_than_or_equal_to: 0.01}
validates :title, uniqueness: true
validates :image_url, allow_blank: true, format: {
with: %r{\.(gif|jpg|png)\z}i,
message: 'Must include an image file extension'
}
end
Something I am not understanding is that we have image_url, allow_blank set to true, but then we have to verify that the image_url is present? This seems like a contradiction to me at first glance, but I'm sure it's from lack of understanding.
What is it that the allow_blank validation is doing? And why do we not validate the :price be present also?