Hi, I can have a Person model with a "has_one :address_email" association, then do the following in my controller: @person = Person.new @person.address_email = AddressEmail.new But, when I have 1 form for "Person" in my view I can''t bind fields in the @person.address_email object with text_field or text_field_tag helpers without getting a "undefined local variable or method. The helpers don''t seem to be able to access the composed/attribute model no matter what syntax I use. I _can_ query the @person.address_email object via a breakpoint console. Page 343 of the Agile book seems to indicate what I''m after is possible: "Form Parameters: user[address][city] = Wien , params: { :user => { :address => { :city => "Wien" }}}" So any ideas? Is it possible to have 1 form with two models where one model is an instance variable of the other? Thanks much for any thoughts! Cheers, JW -- Posted via http://www.ruby-forum.com/.
Mark Reginald James
2006-May-20 10:57 UTC
[Rails] Re: 1 Form for Model containing another Model??
JW wrote:> I can have a Person model with a "has_one :address_email" association, > then do the following in my controller: > > @person = Person.new > @person.address_email = AddressEmail.new > > But, when I have 1 form for "Person" in my view I can''t bind fields in > the @person.address_email object with text_field or text_field_tag > helpers without getting a "undefined local variable or method. The > helpers don''t seem to be able to access the composed/attribute model no > matter what syntax I use.No you can''t do this, though a core patch is available that makes it possible: <http://dev.rubyonrails.org/ticket/2053> Instead I''d suggest using something like: @address_email = @person.build_address_email(params[:address_email]) text_field :address_email, :address1 text_field :address_email, :email -- We develop, watch us RoR, in numbers too big to ignore.
JW
2006-May-31 22:54 UTC
[Rails] Re: 1 Form for Model containing another Model?? [Thx Mark!]
Mark Reginald James wrote:> JW wrote: >> matter what syntax I use. > No you can''t do this, though a core patch is available that makes it > possible: <http://dev.rubyonrails.org/ticket/2053> > > Instead I''d suggest using something like: > > @address_email = @person.build_address_email(params[:address_email]) > > text_field :address_email, :address1 > text_field :address_email, :emailHi Mark, First thanks very much for your help and comment... I was really stumbling hard on that one. Will examine the build_address_email method in ActiveRecord but do hope the core patch makes it in as it seems to be straight-forward. Cheers and thanks again... JW -- Posted via http://www.ruby-forum.com/.