2014-03-04 30 views

回答

2

它看起来像你可以显式排除来自父母或关联或两者的属性。下面直接是一个例子,从文档:

pirate.dup :include => :parrot, :except => [:name, { :parrot => [:name] }] 

对于你的情况,你要离开关:父像这样的名字:

pirate.dup :include => :parrot, :except => [{ :parrot => [:name] }] 

顺便说一句,你还可以包括来自关联的属性,如果您想使用白名单技术,可以满足您的需求。这是直接的例子,从文档:

pirate.dup :include => :parrot, :only => [:name, { :parrot => [:name] }] 

你可能要为白名单做的是这样的:

pirate.dup :include => :parrot, :only => [{ :parrot => [:name] }] 

希望这有助于!

相关问题