0

I have an Owner model wich has_one Address, and accepts_nested_attributes for it. When loading a Owner, for the :new action, I expected the :load_resource method to build the association like @owner.build_address, but this don't happen with the code below:

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

Is this the expected behaviour and I have to do @owner.address = @address by my own ?

Thank you

Gus
  • 942
  • 9
  • 32
  • I have the same problem as you. It seems CanCan builds resources with "Class.new". So it doesn't known the relationship. – gfreezy Dec 03 '12 at 14:06

1 Answers1

0

You may refer to the answer. https://stackoverflow.com/a/7015900/950843

It works for me except I have to ignore both :new and :create actions.

Community
  • 1
  • 1
gfreezy
  • 98
  • 7
  • Thanks for te answer @gfreezy, but I think we are in slightly different contexts. In your example, your controller must load it's own model through a object. In my OwnersController I want to load other model (Address) from the Owner model, thats why I use :parent => false when loading address. Note that I already use the :through option. I interpreted this line of code as following: load_resource :address (load an Address), :through => :owner (for the Owner object), :singleton => true (It's only one Address), :parent => false (this is not AddressesController) – Gus Feb 21 '13 at 14:50