我已经看到了http://rails-bestpractices.com/posts/15-the-law-of-demeter的委托,我喜欢这个,我想像下面这样自定义。
情况1 :
class Application < ActiveRecord::Base
belongs_to :user
delegate :name, :to => :user
has_one :repair, :dependent => :destroy
delegate :estimated_amount, :to => :repair
has_one :dealership, :through => :booking
end
class User < ActiveRecord::Base
def name
return some value
end
end
我打过电话Application.first.user_name => undefined method `user_name' for #<Application:0xb186bf8>
案例2:我打过电话Application.first.repair_estimated_amount: => undefined method `'repair_estimated_amount' for #<Application:0xb186bf8>
案例3:我打过电话Application.first.dealership_name: => undefined method `' for #<Application:0xb186bf8>
有人可以建议如何将委托与 has_one 关系一起使用吗?
在此先感谢普拉萨德