Reputation: 398
For Rails capitalization
, when I use it with a string and try to manually capitalize something else in the sentence, it won't allow me to capitalize it.
eg. "how is New York".capitalize
"How is new york"
Is there anyway in Rails that allows me to ensure the first word is capitalized, but also gives flexibility that if the user capitalizes something else in the string, it will still apply?
Upvotes: 2
Views: 239
Reputation: 6122
if you are using rails 5+ you can use str.upcase_first
other wise the simplest solution will be
str = "how is New York"
str[0] = str[0].upcase
Upvotes: 2