def titleize(string)
string.split(\" \").map {|word| word.capitalize}.join(\" \")
end
This titleizes every single word, but how do I capture cert
If you throw this into config/initializers into a new file (you can name it anything like string.rb), you can call your custom functions to any string. Make sure you restart, and then you will be able to run below like ex) "anystring".uncapitalize_puncs
This is easier than messing around trying to change the default code of titleize. So now, you can just call @something.title.titleize.uncapitalize_puncs
class String
def uncapitalize_puncs
puncs = ["and", "the", "to", "of", "by", "from", "or"]
array = self.split(" ")
array.map! do |x|
if puncs.include? x.downcase
x.downcase
else
x
end
end
return array.join(" ")
end
end