且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过字符串获取 ActiveRecord 对象的属性

更新时间:2023-11-06 10:18:28

所有这些都应该有效:

user[attribute_name]
user.read_attribute(attribute_name)
user.send(attribute_name)

我个人不会在这种情况下使用 send.可用时,首选 public_send 发送

Personally I wouldn't use send in this case. When available, prefer public_send to send