0

Below is my user model. I am trying add a custom message for uniqueness. The custom message I want is 'This User already exist' but it returns 'Name This User already exist'. Please help me find where I am going wrong.

user.rb

class User < ApplicationRecord
 validates :name, uniqueness: { message: 'This User already exist' }, unless: :individual
end
user12763413
  • 1,177
  • 3
  • 18
  • 53
  • Here is one answer, from StackOverlow: https://stackoverflow.com/a/24785730/1954610 – Tom Lord Oct 22 '21 at 18:45
  • Here is a second answer, from StackOveflow: https://stackoverflow.com/a/808776/1954610 – Tom Lord Oct 22 '21 at 18:45
  • Here is a third answer, from StackOverflow: https://stackoverflow.com/a/1156621/1954610 – Tom Lord Oct 22 '21 at 18:46
  • Here is a blog post about it: https://www.bigbinary.com/blog/rails-6-allows-to-override-the-activemodel-errors-full_message-format-at-the-model-level-and-at-the-attribute-level – Tom Lord Oct 22 '21 at 18:46
  • Here is a second blog post about it: https://thepugautomatic.com/2007/12/full-error-messages-without-prepended-attribute-name/ – Tom Lord Oct 22 '21 at 18:48
  • 3
    Does this answer your question? [Fully custom validation error message with Rails](https://stackoverflow.com/questions/808547/fully-custom-validation-error-message-with-rails) – ricks Oct 22 '21 at 18:50

0 Answers0