2

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?

dgreen22
  • 388
  • 4
  • 19

1 Answers1

2

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
Haseeb A
  • 5,356
  • 1
  • 30
  • 34