Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails string helper to remove hyphen and capitalize?

I would like to know if there is a Rails helper method that removes hyphen from the String and capitalizes it.

For instance, let us turn early-bird into Early bird.

I would do

"early-bird".gsub('-', ' ').capitalize

but I would like to know if there is a specific method that does this.

like image 229
Sung Cho Avatar asked Nov 30 '22 17:11

Sung Cho


1 Answers

I think .titleize is the closest you get, it will capitalize all words though, not just the first.

'early-bird'.titleize

will give you "Early Bird".

See: http://api.rubyonrails.org/classes/String.html#method-i-titleize

like image 157
Robert Falkén Avatar answered Dec 28 '22 10:12

Robert Falkén