aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-17 10:18:36 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-17 10:18:36 +0000
commit305a5463bd1caf4d0e2f96d39ef3cbbf455788c6 (patch)
tree2f4847e89fe46130342744d759f8b46566a9d6c9 /activesupport/lib
parente51221871c661cc4e057871fc31d5793f6e992bf (diff)
downloadrails-305a5463bd1caf4d0e2f96d39ef3cbbf455788c6.tar.gz
rails-305a5463bd1caf4d0e2f96d39ef3cbbf455788c6.tar.bz2
rails-305a5463bd1caf4d0e2f96d39ef3cbbf455788c6.zip
Added stripping of _id to String#humanize, so "employee_id" becomes "Employee" #1574 [Justin French]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1854 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb2
-rw-r--r--activesupport/lib/active_support/inflector.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index aa4ff3a74d..65107afaf9 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -32,6 +32,8 @@ module ActiveSupport #:nodoc:
Inflector.classify(self)
end
+ # Capitalizes the first word and turns underscores into spaces and strips _id, so "employee_salary" becomes "Employee salary"
+ # and "author_id" becomes "Author".
def humanize
Inflector.humanize(self)
end
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index be25a93687..149b962579 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -34,7 +34,7 @@ module Inflector
end
def humanize(lower_case_and_underscored_word)
- lower_case_and_underscored_word.to_s.gsub(/_/, " ").capitalize
+ lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
end
def demodulize(class_name_in_module)