I am trying to set up an error warning that users see at the top of the form when they enter data incorrectly. The error message I'm trying to configure relates to model attributes that are in a nested form.
I tried the solution here , which says that you need to edit the file config/locales/en.yml, but that only changes the message, not the model name and attribute that appear before the error message.
I also tried what Billy suggested in his answer , which has the same result. i.e.
1 error forbade saving this pedestrian train:
- Direction directions from "My custom error message"
Is there a way to show a more convenient model name and attribute in my error message, or completely remove them from the error message?
Here is what I have:
config / locale / en.yml
en:
activerecord:
models:
direction: "In the Getting There section"
attributes:
direction:
directions_from: "From field"
errors:
full_messages:
format: "%{message}"
models:
direction:
attributes:
directions_from:
blank: "My Custom Blank Error Message"
Model
class Direction < ActiveRecord::Base
belongs_to :hikingtrail
attr_accessible :directions_by, :directions_desc, :directions_from
validates :directions_from, :presence => {message: "'My Custom Error Message'", :if => Proc.new { |a| a.directions_by? || a.directions_desc? } }
validates :directions_by, :presence => {message: "'My Custom Error Message'", :if => Proc.new { |a| a.directions_from? || a.directions_desc? } }
validates :directions_desc, :presence => {message: "'My Custom Error Message'", :if => Proc.new { |a| a.directions_from? || a.directions_by? } }
end
source
share