Rails override validator message
- by Anand
Hi, I have a site thats served in 2 flavours, English and French. Here's some code
app/views/user/register.html.erb
-----------------
<% form_for .....>
<%= f.text_field :first_name %>
<% end %>
app/models/user.rb
------------------
class User < ActiveRecord::Base
validates_presence_of :first_name
end
Now to display the error message in case if the site is being served in the French version, I have
app/config/locales/fr.yml
-------------------------
activerecord:
errors:
messages:
empty: "ne peut pas être vide"
So if someone does not fill in a first name, the validator takes the name of the field and appends the custom message for empty clause giving
"First name ne peut pas être vide"
which is incorrect, coz 'First name' in French is 'Prénom', hence it should be
"Prénom ne peut pas être vide"
Please can someone suggest a way of achieving the desired result.