如果我们有3种型号=>客户,用户和物与另一种模型业主这就是从用户继承,我们试图建立一个has_many through
协会这样的:的Rails通过与传承问题关联的has_many
class Customer < ActiveRecord::Base
has_many :things, :dependent => :destroy
has_many :owners, through: :things
end
class Thing < ActiveRecord::Base
belongs_to :customer, foreign_key: "customer_id"
belongs_to :owner, foreign_key: "owner_id"
end
class Owner < User
has_many :things, :dependent => :destroy
has_many :customers, through: :things
end
为什么会@owner.things
不为我们工作? (@owner是所有者的一个实例)。它给出了undefined method "things"
错误。
@owner是current_user,但是如何将其指定为User的实例?
是将owner_id
更改为user_id
的唯一解决方案,还是有更好的解决方案吗?
'@ owner'的值是多少? – linkyndy
你确定'@ owner'是'Owner'的一个实例吗? – linkyndy
糟糕,是啊,它是current_user – tilin