Why does Rails titlecase add a space to a name?

前端 未结 10 1165
我在风中等你
我在风中等你 2021-02-05 10:28

Why does the titlecase mess up the name? I have:

John Mark McMillan

and it turns it into:

>> \"john mark McM         


        
10条回答
  •  伪装坚强ぢ
    2021-02-05 10:50

    If you want to handle the case where someone has entered JOHN CAPSLOCK JOE as well as the others, I combined this one:

    class String
      def proper_titlecase
        if self.titleize.split.length == self.split.length
          self.titleize
        else
          self.split(" ").collect{|word| word[0] = word[0].upcase; word}.join(" ")
        end
      end
    end
    

    Depends if you want that kinda logic on a String method ;)

提交回复
热议问题