Skip to content

100% exclusive message for any ActiveModel validation error.

Notifications You must be signed in to change notification settings

yivo/exclusive-error-message

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'

About

100% exclusive message for any ActiveModel validation error.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages