Rails string helper to turn "SimpleProduct" into "Simple Product" or even "simple product"

StackOverflow https://stackoverflow.com/questions/17512827

  •  02-06-2022
  •  | 
  •  

Question

Rails injects a lot of neat helpers into String which it uses for its "magic".

I have a string "SimpleProduct" and want to represent that as "Simple Product".

Right now, I only see how to do this using four of these helpers:

"SimpleProduct".tableize.singularize.humanize.titleize

Is there a cleaner and simpler way? Am I overlooking an obvious helper?

Was it helpful?

Solution

Running directly "SimpleProduct".titleize should do the work

Reference: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-titleize

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top