# Controller/view changes for editing nested forms?

**URL:** <https://www.ruby-forum.com/t/controller-view-changes-for-editing-nested-forms/178486>\
**Category:** Rails\
**Created:** [November 5, 2009, 10:56am UTC](https://www.ruby-forum.com/t/controller-view-changes-for-editing-nested-forms/178486 "2009-11-05T10:56:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Todd\_ASJacobs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@Todd\_ASJacobs](https://www.ruby-forum.com/u/Todd_ASJacobs)\
**Post date:** [November 5, 2009, 10:56am UTC](https://www.ruby-forum.com/t/controller-view-changes-for-editing-nested-forms/178486/1 "2009-11-05T10:56:09Z")

</div>

I’ve successfully set up a nested form from the controller:

def new  
@user = User.new  
@user.build\_contact.build\_address

```
respond_to do |format|
  format.html # new.html.erb
  format.xml { render :xml => @user }
end

```

end

and have edited the new.html.erb file to suit, with fields\_for in the  
appropriate places. The form successfully creates contact and address  
records  
when saved, and I can see linked objects when I simply create them at  
the  
console. However, selecting edit from the index brings up the  
edit.html.erb  
view (practically identical to new.html.erb) but isn’t populating the  
nested  
fields–only the ones from User get populated, but Contact and Address  
remain blank even though the records exist.

Do I need to change something in the edit() to populate the fields for  
the nested objects? I currently have:

def edit  
@user = User.find(params[:id])  
end

Or do I need to change the view somehow to access the nested objects  
differently when I edit than I do when I create?

–  
“Oh, look: rocks!”  
– Doctor Who, “Destiny of the Daleks”
