开发者

Rails: accessing field value from model method

开发者 https://www.devze.com 2023-01-05 02:30 出处:网络
Where title is a field on the table in the database开发者_StackOverflow中文版, why does calling @title return nil?

Where title is a field on the table in the database开发者_StackOverflow中文版, why does calling @title return 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.

0

精彩评论

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