From 3100ec4355320c088e0969bd5caf62c5c0042f4a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 3 Mar 2010 00:05:01 +0100 Subject: AS guide: documents String#humanize --- .../source/active_support_core_extensions.textile | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 149ebefbab..3370939861 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1527,6 +1527,35 @@ end NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +humanize+ + +The method +humanize+ gives you a sensible name for display out of an attribute name. To do so it replaces underscores with spaces, removes any "_id" suffix, and capitalizes the first word: + + +"name".humanize # => "Name" +"author_id".humanize # => "Author" +"comments_count".humanize # => "Comments count" + + +The helper method +full_messages+ uses +humanize+ as a fallback to include attribute names: + + +def full_messages + full_messages = [] + + each do |attribute, messages| + ... + attr_name = attribute.to_s.gsub('.', '_').humanize + attr_name = @base.class.human_attribute_name(attribute, :default => attr_name) + ... + end + + full_messages +end + + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3