Multiple rows problem

edit.rhtml

<% for @patient in @patients %>
<%= text_field “patient[]”, “name” %>
<% end %>

doctor_controller.rb

def update
@doctor = Doctor.find(params[:id])
@params[:patient].each do |id, details|
@patient = @doctor.patients.find(id)
@patient.update_attributes(details)
end
redirect_to …
end

Error -> crashing at update_attributes

Doctor expected, got String

Thanks Alex, I fixed the problem.

The problem is that I was using a column name in the patient table
called doctor and also included doctor_id… any of these will try to
get a doctor, therefore the Doctor expected :slight_smile:

Thanks anyway

Rath — wrote:

edit.rhtml

<% for @patient in @patients %>
<%= text_field “patient[]”, “name” %>
<% end %>

doctor_controller.rb

def update
@doctor = Doctor.find(params[:id])
@params[:patient].each do |id, details|
@patient = @doctor.patients.find(id)
@patient.update_attributes(details)
end
redirect_to …
end

Error -> crashing at update_attributes

Doctor expected, got String

What does params.inspect yeild when you submit the form for this page?
That might help you figure out whats going on.