11

I'm using

validates :feed_id, presence: true, uniqueness: true

How should I be generating a custom error message to specify that the user has already subscribed to this feed (the feed_id) field is a duplicate

I know I can just do validate_uniqueness_of but it would clutter up the code unnecessarily. How do I pass a specific error message if uniqueness validation fails??

1 Answer 1

27

Put a hash with the key message and desired message as the value instead of true:

validates :feed_id, presence: true, uniqueness: {message: "already subscribed"}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.