Is there a way to retrieve failed validations without checking the error message?
If I have a model with validates :name, :presence => true, :uniqueness => true, how can I check if determine what validation failed(was it uniqueness or was it presence?) without doing stuff like:
if error_message == "can't be blank"
# handle presence validation
elsif error_message = "has already been taken"
# handle uniqueness validation
end
There’s a relatively new method that let you do just that, it’s not documented anywhere as far as I know and I just stumbled on it while reading the source code, it’s the
#added?method:Here’s the original pull request: https://github.com/rails/rails/pull/3369