也许是菜鸟问题,也许不是,也许我缺乏 OOT 但我仍然无法回答为什么我无法获得分配给 true 的实例变量 @upgrade 的值。
class OrderTemplate < ActiveRecord::Base
belongs_to :user
attr_writer :upgrade #to hold upgrade process across actions
def upgrade
@upgrade || false
end
def from_time
p self.inspect
------------------------> they looks same
p self.upgrade
------------------------> is true as is supposed to be
p self.user.order_template.inspect
------------------------> they looks same
p self.user.order_template.upgrade
------------------------> is false but i am expecting true
self.user.has_time_bonus?
end
end
class User < ActiveRecord::Base
has_one :order_template
def has_time_bonus?
p self.order_template.upgrade
------------------------> is false but i am expecting true
end
end
请打我。