Rails attributes overriding
I have a Model with an att开发者_C百科riubte "name". I would like to be able to create a getter "name" that returns name.capitalize.
The problem, however, is that when the model is saved, the capitalized name is being written to the database. Suggestions?
def name
attributes["name"].capitalize
end
and better to use another name for method
def capitalized_name # or "cap_name"
name.capitalize
end
def name
read_attribute(:name).capitalize
end
精彩评论