Eric N. wrote:
Is it possible to change the attribute name displayed to the user via
the error_messages_for tag? For example if you wanted to use ‘email’
as an attribute name and db column but ‘e-mail’ as the attribute name
displayed on the webpage.
ActiveRecord::Base::human_attribute_name is responsible for the
transformation, so you could do this, as long as you don’t mind a little
put this in your environment.rb
when ‘email’ then ‘E-mail’
This would override the attribute names anywhere they’re humanized for
display (which is probably what you want). Besides error messages, this
includes scaffold templates and other generated code. If you don’t want
that, you should probably just write your own error_messages_for (by
accessing object.errors) as the docs suggest.
One other caveat – there’s a test that covers this, in
(test_human_name_for_column). It’ll fail if you change the humanization
of a column named ‘author_name’.