FogBugz #62: aim at using a nested form for entering the address.
This commit is contained in:
parent
7bbf17314d
commit
32cdb53c26
3 changed files with 28 additions and 8 deletions
|
|
@ -8,6 +8,8 @@ class ContactsController < ApplicationController
|
|||
|
||||
def new
|
||||
@contact = Contact.new
|
||||
# @contact.address = Address.new
|
||||
@contact.build_address
|
||||
email = @contact.emails.build
|
||||
phone = @contact.phones.build
|
||||
setup_months_and_days
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
class Contact < ActiveRecord::Base
|
||||
has_many :emails, :dependent => :destroy
|
||||
has_many :phones, :dependent => :destroy
|
||||
|
||||
belongs_to :address
|
||||
accepts_nested_attributes_for :address
|
||||
|
||||
accepts_nested_attributes_for :emails, :reject_if => lambda { |a| a[:address].blank? }, :allow_destroy => true
|
||||
accepts_nested_attributes_for :phones, :reject_if => lambda { |a| a[:nr].blank? }, :allow_destroy => true
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<%= form_for @contact, :html => {:class => "new_data_form"} do |f| %>
|
||||
<% form_for @contact, :html => {:class => "new_data_form"} do |f| %>
|
||||
<fieldset>
|
||||
<legend>Contact details</legend>
|
||||
<table>
|
||||
|
|
@ -10,25 +10,41 @@
|
|||
<td align="right"><%= label_tag(:lastname, "Last name") %></td>
|
||||
<td><%= f.text_field :lastname %></td>
|
||||
</tr>
|
||||
|
||||
<!-- temp -->
|
||||
<tr>
|
||||
<td align="right"><%= label_tag(:street, "Street name") %></td>
|
||||
<td><%= f.text_field :street %></td>
|
||||
<td colspan="2">
|
||||
<% if @contact.address.nil? %>
|
||||
address: nil
|
||||
<% else %>
|
||||
address: hat was
|
||||
street: <%= @contact.address.street %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<% f.fields_for :address do |address_f| %>
|
||||
<tr>
|
||||
<td align="right"><%= address_f.label :street, "Street name" %></td>
|
||||
<td><%= address_f.text_field :street %></td>
|
||||
<tr>
|
||||
<td align="right"><%= label_tag(:housenr, "House number") %></td>
|
||||
<td><%= f.text_field :housenr %></td>
|
||||
<td><%= address_f.text_field :housenr %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right"><%= label_tag(:plz, "Zip code") %></td>
|
||||
<td><%= f.text_field :plz %></td>
|
||||
<td align="right"><%= label_tag(:zipcode, "Zip code") %></td>
|
||||
<td><%= address_f.text_field :zipcode %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right"><%= label_tag(:place, "Place") %></td>
|
||||
<td><%= f.text_field :place %></td>
|
||||
<td><%= address_f.text_field :place %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right"><%= label_tag(:country, "Country") %></td>
|
||||
<td><%= f.text_field :country %></td>
|
||||
<td><%= address_f.text_field :country %></td>
|
||||
</tr>
|
||||
<% end %> <%# fields_for :adress %>
|
||||
|
||||
<% f.fields_for :emails do |emails_f| %>
|
||||
<%= render "email_fields", :f => emails_f %>
|
||||
<% end %> <%# fields_for :emails %>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue