0

我的用户写了他们的名字和姓氏,没有大写

有没有办法覆盖模型的 getterfirstnamelastname属性以User使其返回firstname.capitalize

如果我做

def firstname
 self.firstname.capitalize
end

我明白了stack too deep error

4

1 回答 1

1

如果您使用与属性相同的名称,则需要使用 read_attribute

def firstname
  read_attribute(:firstname).capitalize
end
于 2013-03-07T09:26:51.560 回答