Method: String#humanize
- Defined in:
- lib/active_support/core_ext/string/inflections.rb
permalink #humanize(capitalize: true, keep_id_suffix: false) ⇒ Object
Capitalizes the first word, turns underscores into spaces, and (by default) strips a trailing ‘_id’ if present. Like titleize
, this is meant for creating pretty output.
The capitalization of the first word can be turned off by setting the optional parameter capitalize
to false. By default, this parameter is true.
The trailing ‘_id’ can be kept and capitalized by setting the optional parameter keep_id_suffix
to true. By default, this parameter is false.
'employee_salary'.humanize # => "Employee salary"
'author_id'.humanize # => "Author"
'author_id'.humanize(capitalize: false) # => "author"
'_id'.humanize # => "Id"
'author_id'.humanize(keep_id_suffix: true) # => "Author id"
See ActiveSupport::Inflector.humanize.
262 263 264 |
# File 'lib/active_support/core_ext/string/inflections.rb', line 262 def humanize(capitalize: true, keep_id_suffix: false) ActiveSupport::Inflector.humanize(self, capitalize: capitalize, keep_id_suffix: keep_id_suffix) end |