The .capitalize! function doesn’t seem to work inside a model in Rails.
Is there a way around this? I have a valid business case for using this in a model by the way.
Here’s the code that’s throwing me an error:
def something
...
str.strip
str.capitalize!
end
Error I get is can't convert nil into String
Everything works find if I remove the last line.
Edit: Sorry, I had a brain fart! Fixed it.
What’s wrong with writing just
"string".capitalize!?It’s just a ruby String method, http://www.ruby-doc.org/core-1.9.3/String.html#method-i-capitalize-21
upd
and as it’s obvious now, the problem was the string you were trying to update was nil