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 %> <p> <b><%= column.human_name %>:</b> <%=h @group.send(column.name) %> </p> <% end %>
<%= link_to 'Edit', :action => 'edit', :id => @group %> | <%= link_to 'Back', :action => 'list' %>
<br/> <hr/>
<% for contact in @group.contacts %> <%= contact.first %><br/> <%= contact.name %><br/> <%= contact.adress %> <hr /> <% end %>
<%= form_tag :action => "contact", :id => @group, : %> <span>First: </span><%= text_field "contact", "first" %> <span>Last: </span><%= text_field "contact", "name" %> <span>Adress: </span><%= text_field "contact", "adress" %> <span>City: </span><%= text_field "contact", "city_name" %> <%= submit_tag "Add contact!" %> </form>
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