0
我有两种款式Board
和Feed
与多对多的关系加入:通过型号Subscription
。凌驾收藏<<方法
最近我加入root_id
领域Subscription
,我想安装这个领域,当我做@board.feeds << @feed
所以它会像@board.feeds << @feed, root_id: 10
根据轨道的文档,我可以重写这些方法,但不知道如何。
def feeds << (??? - how should I setup arguments here?)
super
#super creates new Subscription rekord, but how can I access it
#to set root_id field?
#For now let say I accessed it as subscription
if root_id
subscription.root_id = root_id
else
subscription.root_id = self.id
end
subscription.save
#return something regular collection << returns
end
覆盖这样的方法很少是一个好主意。我只想定义一个像'def add_feed feed'这样的订阅方法,并且在那里做所有额外的东西,并使用它来代替使用'<<'。 – p1100i