3
如果您編寫my_obj.attr
,主要在導軌中,它在數據庫中查找attr
並報告回來。你如何創建一個自定義def attr
方法,內部查詢attr
數據庫,修改它並返回?換句話說,什麼是缺失的環節在這裏:導軌中的定製attr_reader
# Within a model. Basic attr_reader method, will later modify the body.
def attr
get_from_database :attr # <-- how do I get the value of attr from the db?
end
這個問題本身實際上是什麼的意思有點不清楚你的時候做「修改「的價值。如果你不想存儲它,那麼顯然沒有必要保存模型:) – 2010-01-27 10:38:17
def attr self [:attr] .capitalize end 也可以工作 – psyho 2010-01-27 15:24:31