Ruby on Rails Tuesday, December 20, 2016

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


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/11134a17-b942-4fa7-a1c2-88cdbcbde12a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment