Does rails have an opposite of 'humanize' for strings?

In http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html you have some methods used to prettify and un-prettify strings.


There doesn't appear to be any such method in the Rail API. However, I did find this blog post that offers a (partial) solution: http://rubyglasses.blogspot.com/2009/04/dehumanizing-rails.html


the string.parameterize.underscore will give you the same result

"Employee salary".parameterize.underscore       # => employee_salary
"Some Title: Sub-title".parameterize.underscore # => some_title_sub_title

or you can also use which is slightly more succinct (thanks @danielricecodes).

  • Rails < 5 Employee salary".parameterize("_") # => employee_salary
  • Rails > 5 Employee salary".parameterize(separator: "_") # => employee_salary