diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/inflections.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/inflector.rb | 2 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 1 |
4 files changed, 6 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index b8abb21a88..f56f9cd51e 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added stripping of _id to humanize, so "employee_id" becomes "Employee" #1574 [Justin French] + * Added Fixnum#ordinalize to turn 1.ordinalize to "1st", 3.ordinalize to "3rd", and 10.ordinalize to "10th" and so on #1724 [paul@cnt.org] 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) diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 2d69431cd4..26aea141fe 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -128,6 +128,7 @@ class InflectorTest < Test::Unit::TestCase UnderscoreToHuman = { "employee_salary" => "Employee salary", + "employee_id" => "Employee", "underground" => "Underground" } |