I have two validations..
validates_presence_of :name
validate :category?
In my category?
validation, it asks for a Model.category.downcase
method. I made a spec where no category exists, and it is failing in my specs because no category exists for it to downcase.
My question is, how do I set up my model to first validate if the name exists. If it doesn't then don't go on to the next validation. Or is that not really proper?
A Failing Method
if self.category
unless Category.exists?(:name => self.category.downcase)
errors.add(:category, "There's no categories with that name.")
end
return true
end
A Working Copy
def category?
if self.category
unless Category.exists?(:name => self.category.downcase)
errors.add(:category, "There's no categories with that name.")
end
return true
end
end
Can't just that one validation work as a gateway to the following? For example, if it fails to have a name, then why does it keep going through the rest of the validations?