Skip to content

Instantly share code, notes, and snippets.

@vinhnglx
Created March 11, 2016 17:10
Show Gist options
  • Save vinhnglx/a5ceefd6405be7f134dd to your computer and use it in GitHub Desktop.
Save vinhnglx/a5ceefd6405be7f134dd to your computer and use it in GitHub Desktop.
Custom validation message in Rails - Override prefix
class User < ActiveRecord::Base
validates_uniqueness_of :email, message: 'has already taken'
end
# user = User.new(email: 'foo@bar.com')
# user.save! => User has already taken.
# If you wanna change the error message to "Your fucking account has already taken"
# just edit one file config/locales/en.yml
en:
activerecord:
attributes:
user:
email: 'Your fucking account'
Copy link

ghost commented Mar 12, 2016

'Your fucking account' --> LOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment