Rails: accessing field value from model method
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.
精彩评论