Hi,
I Try to Add to one of my Group objects a Contact object
My model looks simplified like this:
Group has a Contacts
Contact has a Group
Contact has a City
City is owned by Contacts
I hope thats understandable.
My Form:
<% for column in Group.content_columns %>
<%= column.human_name %>: <%=h @group.send(column.name) %>
<% end %><%= link_to ‘Edit’, :action => ‘edit’, :id => @group %> |
<%= link_to ‘Back’, :action => ‘list’ %>
<% for contact in @group.contacts %>
<%= contact.first %>
<%= contact.name %>
<%= contact.adress %>
<% end %>
<%= form_tag :action => “contact”, :id => @group, : %>
First: <%= text_field “contact”, “first” %>
Last: <%= text_field “contact”, “name” %>
Adress: <%= text_field “contact”, “adress” %>
City: <%= text_field “contact”, “city_name” %>
<%= submit_tag “Add contact!” %>
in the controller the method looks like this:
def contact
newContact = Group.find(params[:id]).contacts.create
newContact.first = params[:first]
newContact.name = params[:name]
newContact.name = params[:adress]
existingCity = City.find_on_conditions(:all, :name =>
params[:city_name])
newContact.reload
if (existingCity[0] != nil) then
newContact.city = existingCity[0]
else
newContact.city = City.create
newContact.city.name = params(:city_name)
end
flash[:notice] = "Added your new contact."
redirect_to :action => "show", :id => params[:id]
end
the following ErrorMessage reads like this:
“Couldn’t find Contact without an ID”
#{RAILS_ROOT}/app/controllers/rails_contacts_controller.rb:58:in
`contact’
Its probably a really stupid mistake. I started Ruby 2 days before so
be gentle
Thanks in Advance