Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 305a5463bd1caf4d0e2f96d39ef3cbbf455788c6 1 parent e512218
@dhh dhh authored
View
2  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]
View
2  activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -32,6 +32,8 @@ def classify
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
View
2  activesupport/lib/active_support/inflector.rb
@@ -34,7 +34,7 @@ def underscore(camel_cased_word)
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)
View
1  activesupport/test/inflector_test.rb
@@ -128,6 +128,7 @@ class InflectorTest < Test::Unit::TestCase
UnderscoreToHuman = {
"employee_salary" => "Employee salary",
+ "employee_id" => "Employee",
"underground" => "Underground"
}
Please sign in to comment.
Something went wrong with that request. Please try again.