No commit activity in last 3 years
No release in over 3 years
100% exclusive message for any ActiveModel validation error.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

< 6.0, >= 3.0
 Project Readme

Allows to specify 100% exclusive message for any ActiveModel validation error.

Gem Version

Usage

Summary

Prefix any error message with _ and it will become full message omitting I18n(:'errors.format', ...) processing.

Before

class Post < ActiveRecord::Base
  validates :title, presence: { message: "Sorry, but title can't be empty" }
end

post = Post.new
post.validate

# Get full messages for errors:
post.errors.to_hash(true) # => { title: "Title: Sorry, but title can't be empty" }

After

class Post < ActiveRecord::Base
  validates :title, presence: { message: "_Sorry, but title can't be empty" }
end

post = Post.new
post.validate

# Get full messages for errors:
post.errors.to_hash(true) # => { title: "Sorry, but title can't be empty" }

Usage in localizations

en:
  activerecord:
    errors:
      models:
        post:
          attributes:
            title:
              blank: _Sorry, but title can't be empty

Adding error manually

post   = Post.new
errors = post.errors

errors.add(:title, "_Sorry, but title can't be empty")

# Get full messages for errors:
post.errors.to_hash(true) # => { title: "Sorry, but title can't be empty" }

Installation

Add to your Gemfile:

gem 'exclusive-error-message', '~> 1.0'