class method
self.human_attribute_name
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
self.human_attribute_name(attribute_key_name, options = {})
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"
This used to be depricated in favor of humanize, but is now preferred, because it automatically uses the I18n module now. Specify options with additional translating options.
Parameters
-
attribute_key_namereq -
optionsopt = {}
Source
# File activerecord/lib/active_record/base.rb, line 1395
def human_attribute_name(attribute_key_name, options = {})
defaults = self_and_descendants_from_active_record.map do |klass|
:"#{klass.name.underscore}.#{attribute_key_name}"
end
defaults << options[:default] if options[:default]
defaults.flatten!
defaults << attribute_key_name.to_s.humanize
options[:count] ||= 1
I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => [:activerecord, :attributes]))
end
Defined in activerecord/lib/active_record/base.rb line 1395
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Base