While trying to deal with error messages for attributes of models
using STI, I stumbled upon the human_attribute_name method...
# Transforms attribute key names into a more humane format, such
as "First name" instead of "first_name". Example:
# Person.human_attribute_name("first_name") # => "First
name"
# Deprecated in favor of just calling "first_name".humanize
def human_attribute_name(attribute_key_name) #:nodoc:
attribute_key_name.humanize
end
I''m wondering if it really is deprecated.
It''s still in use in validations for adding errors, and I think
it''s a
great solution for having a shared column in a base model that can be
reported as having an error differently depending on the subclass
using STI.
For example, I have an Address model with subclasses of EmailAddress
and WebAddress and the "address" attribute will contain an email
address or a url for the respective classes.
By overriding human_attribute_name in my subclasses I can make my
error messages friendlier. If the method goes away, I''m not sure how
I''d do it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---
> For example, I have an Address model with subclasses of EmailAddress > and WebAddress and the "address" attribute will contain an email > address or a url for the respective classes. > > By overriding human_attribute_name in my subclasses I can make my > error messages friendlier. If the method goes away, I''m not sure how > I''d do it.I don''t know that there''s any plan to remove this method, if you''d kept quiet it would probably have lived on forever ;). In the meantime I think we can view it as a ''hook'' for customisation rather than as part of the stable API intended for surviving indefinitely. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> I don''t know that there''s any plan to remove this method, if you''d > kept quiet it would probably have lived on forever ;). In theI considered that, but didn''t want my code breaking when rails 2.3 came out ;-) cheers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---