Rails adds a humanize()
method for strings that works as follows (from the Rails RDoc):
\"employee_salary\".humanize # => \"Employee salary\"
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
In http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html you have some methods used to prettify and un-prettify strings.
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).
Employee salary".parameterize("_") # => employee_salary
Employee salary".parameterize(separator: "_") # => employee_salary