I’m guessing this one is very simple but I’m just not sure how to google for it.
I have a User model with a Name column where name is a lowercased string. I want to configure my model so that string.titleize is called any time the name value is retrieved.
currently:
user = User.find(89)
user.name
==> 'larry david'
but i want
user.name
==> 'Larry David'
I want this built into the model so that I don’t have to call ‘.titleize’ in all of my views
thanks!
Override Rails’ attribute accessor method:
Note: The
trymethod will silently avoid aNoMethodErrorexception when the name attribute isnil.