Nested Form Error

13 views
Skip to first unread message

Juliano Vieira

unread,
Dec 22, 2016, 5:17:05 AM12/22/16
to Ruby on Rails: Talk
I'm trying to apply the template below and it returns me "Appointments physician must exist"; How can I solve?

class Physician < ApplicationRecord
    has_many
:appointments
    has_many
:patients, through: :appointments

    accepts_nested_attributes_for
:appointments, reject_if: :all_blank, allow_destroy: true
end

class Patient < ApplicationRecord
    has_many
:appointments
    has_many
:physicians, through: :appointments
end

class Appointment < ApplicationRecord
  belongs_to
:physician
  belongs_to
:patient

  accepts_nested_attributes_for
:patient, reject_if: :all_blank, allow_destroy: true
end

   
def physician_params
           
params.require(:physician).permit(:name, :appointments_attributes => [:id, :appointment_date, :physician_id, :patient_id,:_destroy, :patient_attributes => [:id, :name]])
   
end

log servidor

Started POST "/physicians" for 127.0.0.1 at 2016-12-19 09:51:52 -0200
Processing by PhysiciansController#create as HTML
 
Parameters: {"utf8"=>"✓", "authenticity_token"=>"WYPs+WSFG0Pj8fzv16ob0QB+Xy33zxm2o7jX6G7mHUj4xmr91djbRap+59W3eeh9Hslp6y2dtMUz9MN7aV5bfQ==", "physician"=>{"name"=>"jeca", "appointments_attributes"=>{"1482148308254"=>{"appointment_date(1i)"=>"2016","appointment_date(2i)"=>"12", "appointment_date(3i)"=>"19", "appointment_date(4i)"=>"11", "appointment_date(5i)"=>"51","patient_attributes"=>{"name"=>"Juca Bala"}, "_destroy"=>"false"}}}, "commit"=>"Create Physician"}
   
(0.1ms)  begin transaction
   
(0.1ms)  rollback transaction
 
Rendering physicians/new.html.erb within layouts/application
 
Rendered physicians/_appointment_fields.html.erb (3.9ms)
 
Rendered physicians/_appointment_fields.html.erb (3.7ms)
 
Rendered physicians/_form.html.erb (15.0ms)
 
Rendered physicians/new.html.erb within layouts/application (16.3ms)
Completed 200 OK in 51ms (Views: 42.6ms | ActiveRecord: 0.2ms


Reply all
Reply to author
Forward
0 new messages