Fogbugz #60: Anlegen auch von (nested) Phones ermoeglichen.

This commit is contained in:
gchq 2011-05-22 22:20:31 +02:00
parent 2818f5a708
commit 5bbf91a747
3 changed files with 29 additions and 1 deletions

View file

@ -9,6 +9,7 @@ class ContactsController < ApplicationController
@contact = Contact.new
3.times do
email = @contact.emails.build
phone = @contact.phones.build
end
end
@ -22,7 +23,7 @@ class ContactsController < ApplicationController
c.place = params[:contact][:place]
c.country = params[:contact][:country]
# these come as: ["0", {"address"=>"a@b.c"}]
# emails come as: ["0", {"address"=>"a@b.c"}]
params[:contact][:emails_attributes].map {|k,vs| vs}.each { |val|
unless val["address"].blank?
email = c.emails.build
@ -30,6 +31,14 @@ class ContactsController < ApplicationController
end
}
# phones come as: {"0"=>{"nr"=>"+49123456789"}, "1"=>{"nr"=>"..."}}
params[:contact][:phones_attributes].map {|k,vs| vs}.each { |val|
unless val["nr"].blank?
phone = c.phones.build
phone.nr = val["nr"]
end
}
if c.save
flash[:notice] = 'Kontakt hervorragend angelegt!'
redirect_to :action => 'index'

View file

@ -38,6 +38,15 @@
<%= link_to 'Add an email', '#emails', :class => "add_nested_item", :rel => "emails" %>
</td>
</tr>
<% f.fields_for :phones do |phones_f| %>
<%= render "phone_fields", :f => phones_f %>
<% end %> <%# fields_for :phones %>
<tr>
<td>&nbsp;</td>
<td>
<%= link_to 'Add a phone', '#phones', :class => "add_nested_item", :rel => "phones" %>
</td>
</tr>
<tr>
<td align="right"><td><%= f.submit("Save contact") %></td>
</tr>

View file

@ -0,0 +1,10 @@
<tr>
<td align="right"><%= f.label :address, "Phone" %></td>
<td><%= f.text_field :nr %></td>
</tr>
<% unless f.object.new_record? %>
<tr>
<td align="right"><%= f.label :_delete, "Remove Phone" %></td>
<td><%= f.check_box :_delete %></td>
</tr>
<% end %>