Have been dealing with this issue for some time and searched through the whole net, but nothing seems to be useful.
I'm trying to post data through a link_to tag like this:
// get_doctors.html.erb
<%= link_to "Ekle", patient_add_doctor_path(id: @patient.id), data: { doctor: doctor.id }, method: :post %>
However, at the controller, I can not reach the data in my controller.
// patients_controller.rb
def add_doctor
patient = Patient.find(params[:id].to_i)
doctor = Doctor.find(params[:doctor].to_i) // problem is here!
patient.doctors << doctor
end
It gives me the error that params[:doctor] is 0.
Couldn't find Doctor with 'id'=0 [WHERE "users"."type" IN ('Doctor')]
Have tried many different ways. Tried also this,
<%= link_to "Ekle", patient_add_doctor_path(id: @patient.id), doctor: doctor.id, method: :post %>
which is also did not worked.