HighDots Forums  

Controller/view changes for editing nested forms?

Ruby On Rails Talk Ruby On Rails programming language mailing list


Discuss Controller/view changes for editing nested forms? in the Ruby On Rails Talk forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Todd A. Jacobs
 
Posts: n/a

Default Controller/view changes for editing nested forms? - 11-05-2009 , 04:54 AM






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"


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.