On Dec 30, 2:06 am, Colin Law <clan...@googlemail.com> wrote:
> On 30 December 2010 04:32, Geo Manickam <geo...@hotmail.com> wrote:
>
> > I tried address still not able to display the address form.
>
> > <% person_form.fields_for :address do |address_form| %>
>
> Please don't top post, insert your comments at appropriate points in
> the previous message. It makes it easier to follow the thread.
> Thanks.
>
> What do you mean by not able to display address form? Is there an
> error shown? If not then what does the generated html look like? If
> the html is not correct then what is wrong with it?
basically the code inside the <%
person_form.fields_for :address do |address_form| %> is not
executed. i.e in the html page the label and edit boxes for address is
not displayed to the user. and if you look at view source you dont see
the html tags for them. if you move this code below inside fields_for,
no object information is displayed.
<%= debug(@person.address.attributes) %>
<%= debug(@person.address) %>
if there is better way (work around) to handle one-one mapping.
please let me know as well.
> Colin
>
>
>
>
>
>
>
>
>
> > thanks
> > Geo
>
> > On Dec 29, 8:34 am, Colin Law <clan...@googlemail.com> wrote:
> >> 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-talk@googlegroups.com.
> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> >> > For more options, visit this group athttp://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-talk@googlegroups.com.
> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://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-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment