Further updates on my question above:
what if I have a helper method to store the “current_patient”, having always the last patient from my search query and on my hospitalizations_controller I build the Create method something like this: @hospitalization = current_patient.hospitalizations.new(hospitalization_params) ? Would this be the best way to work around this?
This is a great use case for nested resource routing - you aren’t just trying to make a hospitalization, you’re trying to make one for a particular patient. So instead of a route like:
you’d want to use:
One way to read this is “make a new hospitalization for the patient :patient_id”.
To do this in the routes file, you’d have something like:
resources :patients do
You can make a link to the new page with something like (in an ERB template):
link_to “New Hospitalization”, new_patient_hospitalization_path(@patient)
assuming you’ve got the desired patient record in @patient.