如何从模型内部访问属性 [英] How to access attributes from inside a model
本文介绍了如何从模型内部访问属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为item的模型,该模型有一个名为price的列.我假设价格将作为实例变量存储在item内,但是方法
I have a model named item that has a column named price. I assumed that price would be stored as an instance variable inside item but the method
def price
@price
end
不返回任何内容.因此,我的问题是如何从模型内部访问和覆盖从数据库中提取的价值价格.
Returns nothing. So my question is how can I access and override the value price pulled from the database from inside my model.
推荐答案
您可以根据 查看全文