ActiveRecord::Errors best practices?


#1

I’m currently reviewing some old code from Rails 1.x times and found
this:

ActiveRecord::Errors.default_error_messages = {
:inclusion => “inclusion|”,
:exclusion => “exclusion|”,
:invalid => “invalid|”,
:confirmation => “confirmation|”,
:accepted => “accepted|”,
:empty => “empty|”,
:too_long => “too_long|”,
:too_short => “too_short|”,
:wrong_length => “wrong_length|”,
:taken => “taken|”,
:not_a_number => “not_a_number|”,
}

Used on controller code to check if a specific error happens, like this:

if @user.errors.on(“email”).to_s.include? “taken|”

end

Are there better practices for doing this?