I am trying to get Rails to use the first character of the string and leave everyone else as they are. I run into a problem when "I'm from New York" turns into "I'm from New York."
What method would I use to select the first character?
thank
EDIT: I tried to implement what the matzek suggested, but I get an error "
def fixlistname! self.title = self.title.lstrip + (title.ends_with?("...") ? "" : "...") self.title[0] = self.title[0].capitalize errors.add_to_base("Title must start with \"You know you...\"") unless self.title.starts_with? 'You know you' end
EDIT 2:. He works. Thanks for the help!
EDIT 3: Wait, no, I didn’t ... This is what I have in my list model.
def fixlistname! self.title = self.title.lstrip + (title.ends_with?("...") ? "" : "...") self.title.slice(0,1).capitalize + self.title.slice(1..-1) errors.add_to_base("Title must start with \"You know you...\"") unless self.title.starts_with? 'You know you' end
EDIT 4: Fixed editing macek and still getting the `w91>` capize 'error. What can i do wrong?
def fixlistname! self.title = title.lstrip self.title += '...' unless title.ends_with?('...') self.title[0] = title[0].capitalize errors.add_to_base('Title must start with "You know you..."') unless title.starts_with?("You know you") end
EDIT 5: This is strange. I can get rid of an undefined method error using the line below. The problem is that it seems to replace the first letter with a number. For example, instead of smoothing y into You, it turns y into 121
self.title[0] = title[0].to_s.capitalize
string ruby-on-rails capitalization
Daniel O'Connor Apr 15 2018-10-15T00: 00Z
source share