Rails 3: how to generate custom error message from failed validation

ruby, ruby-on-rails, ruby-on-rails-3, validation

Solution

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"}

Problem

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

Original source