嵌套资源的cancan load_resource不构建has_one关联

时间:2012-11-07 18:19:10

标签: ruby-on-rails cancan

我有一个拥有has_one地址的所有者模型,并接受了accept_nested_attributes。加载所有者时,对于:new操作,我期望:load_resource方法构建像@ owner.build_address这样的关联,但是下面的代码不会发生这种情况:

class OnwersController < ApplicationController
    load_and_authorize_resource
    load_resource :address, :through => :owner, :singleton => true, :parent => false

这是预期的行为,我必须自己做@ owner.address = @address吗?

谢谢

1 个答案:

答案 0 :(得分:0)

您可以参考答案。 https://stackoverflow.com/a/7015900/950843

它对我有用,除了我必须忽略两者:new和:create actions。

相关问题