Ruby-on-rails – Ruby on Rails: errors.add_to_base vs. errors.add


I have read that errors.add_to_base should be used for errors associated with the object and not a specific attribute. I am having trouble conceptualizing what this means. Could someone provide an example of when I would want to use each?

For example, I have a Band model and each Band has a Genre. When I validate the presence of a genre, if the genre is missing should the error be added to the base?

The more examples the better

Thank you!

Best Solution

It's worth noting (since this shows up in the search engines, which is how I found it) that this is deprecated. The Rails 3 way of doing it is:

errors[:base] << "Error message"    


errors.add(:base, "Error message")