开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜