Possible Duplicate:
Custom model attribute (column name) title in Ruby on Rails
I've been using this solution in Rails 2.x forever:
HUMANIZED_ATTRIBUTES = {
:email => "E-mail address"
}
def self.human_attribute_name(attr)
HUMANIZED_ATTRIBUTES[attr.to_sym] || super
end
but this causes bizarre errors when getting the errors
from an ActiveRecord instance. What is the correct way to get nice, human-readable names in Rails 3.x?
I think the correct Rails 3 approach would be to use the translation api, but I'm using human_attribute_name as follows:
def self.human_attribute_name(attr, options = {})
HUMANIZED_ATTRIBUTES[attr.to_sym] || super
end
The call to super may be expecting the options argument to be there.
Using human_attribute_name with the I18n framework is more simple I think :
In your view : User.human_attribute_name("email")
In your locale yml file :
en:
activerecord:
attributes:
user:
email: E-mail address
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With