diff options
author | Xavier Noria <fxn@hashref.com> | 2010-03-03 00:05:01 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-03-03 00:05:01 +0100 |
commit | 3100ec4355320c088e0969bd5caf62c5c0042f4a (patch) | |
tree | 9afefaf8831daf8719b91e8314a2d97a3d48e22f /railties/guides | |
parent | 8627281e3b75dbafc0adee7ab4f3d28a177aa9e5 (diff) | |
download | rails-3100ec4355320c088e0969bd5caf62c5c0042f4a.tar.gz rails-3100ec4355320c088e0969bd5caf62c5c0042f4a.tar.bz2 rails-3100ec4355320c088e0969bd5caf62c5c0042f4a.zip |
AS guide: documents String#humanize
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 29 |
1 files changed, 29 insertions, 0 deletions
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: + +<ruby> +"name".humanize # => "Name" +"author_id".humanize # => "Author" +"comments_count".humanize # => "Comments count" +</ruby> + +The helper method +full_messages+ uses +humanize+ as a fallback to include attribute names: + +<ruby> +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 +</ruby> + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes |