On 29 December 2010 07:52, Geo Manickam <geo...@hotmail.com> wrote: > I am new to rails, coming from .net. I am having the issue for 1:1 > mapping nested model view the form will not render. > > I have the code below. note the address object is created. I dont see > the label and text box. the person form render without any issue. the > debug works outside the fields_for. > > Any help is appreciated > > thanks > Geo > > Model > ====== > > class Person < ActiveRecord::Base > has_one :address > accepts_nested_attributes_for :address > end > > > class Address < ActiveRecord::Base > belongs_to :person > end > > Controller > ======== > > GET /people/new > # GET /people/new.xml > def new > �...@person = Person.new > �...@address = @person.address = @person.build_address > > respond_to do |format| > format.html # new.html.erb > format.xml { render :xml => @person } > end > end > > View: _form.html.erb > > > <%= form_for(@person) do |person_form| %> > <% if @person.errors.any? %> > <div id="error_explanation"> > <h2><%= pluralize(@person.errors.count, "error") %> prohibited > this person from being saved:</h2>s > <ul> > <% @person.errors.full_messages.each do |msg| %> > <li><%= msg %></li> > <% end %> > </ul> > </div> > <% end %> > <div class="field"> > <%= person_form.label :name %><br /> > <%= person_form.text_field :name %> > </div> > <div class="field"> > <%= person_form.label :email %><br /> > <%= person_form.text_field :email %> > </div> > <div class="field"> > <%= person_form.label :phone %><br /> > <%= person_form.text_field :phone %> > </div> > <h1>outside</h1> > <%= debug(@person.address.attributes) %> > <%= debug(@person.address) %> > <% person_form.fields_for �...@address do |address_form| %>
I think that should be :address not @address, it specifies the association to use. Colin > <h1>inside form</h1> > <div class="field"> > <%= address_form.label :addressline1 %><br /> > <%= address_form.text_field :addressline1 %> > </div> > <div class="field"> > <%= address_form.label :addressline2 %><br /> > <%= address_form.text_field :addressline2 %> > </div> > <% end %> > <div class="actions"> > <%= person_form.submit %> > </div> > <% end %> > > -- > 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-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.