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" }
Add to your Gemfile:
gem 'exclusive-error-message', '~> 1.0'