ActiveRecord::Errors best practices?

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

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|”


Are there better practices for doing this?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs