[英]Rails: accessing field value from model method
Where title
is a field on the table in the database, why does calling @title
return nil
? 如果
title
是数据库表中的一个字段,为什么调用@title
返回nil
?
Unbelievably, accessing model fields from inside a method on that model is undocumented. 令人难以置信的是,未记录从该模型上的方法内部访问模型字段的信息。
Think about how you would access the info from outside the model: 考虑一下如何从模型外部访问信息:
model_instance.field_name
Therefore, from within the model you simply call 因此,您只需在模型中调用
field_name
you can call instance methods from within that instance. 您可以从该实例中调用实例方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.