Ruby on Rails
Thursday, January 15, 2015
Also checkout accepted_nested_resource I think it is? I'm on my phone currently...this would be placed in your model
--Rob
Sent from my cell, please excuse any typos.
On Jan 15, 2015 1:04 PM, "Diego Dillenburg Bueno" <diegodillenburg@gmail.com> wrote:
-- Thanks for the reply. That would mean building a namespace like Patients > Hospitalization? Nesting Hospitalization inside Patients, right? Will try this. For now I had solved this issue storing the patient_id in the session, any information on this solution? If it's ok or not to use it like that?--
2015-01-15 2:17 GMT-02:00 Matt Jones <al2o3cr@gmail.com>:--
On Tuesday, 13 January 2015 11:22:14 UTC-5, Diego Dillenburg Bueno wrote: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:/hospitalizations/newyou'd want to use:/patients/:patient_id/hospitalizations/newOne 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 doresources :hospitalizationsendYou 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.--Matt Jones2015-01-13 10:50 GMT-02:00 Diego Dillenburg Bueno <diegodi...@gmail.com>:Thanks in advance,Hey there,I have a patients model which has many hospitalizations, from the patients#show I want to generate a link to hospitalizations#new creating a new association to this very same patient, any ideas on how to do that? I want it to when I get to the hospitalizations#ne I be able to manipulate the output the patient data in the generated view and submit a Patient.hospitalizations.create, how would be the best approach for that?
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/3b5be9c1-6efc-4920-85d6-9a89c52a008f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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/CAOHSkmHW%3DFa1YirbuBXmnBmhJecVGqQ8yDK6qDT98bgBjZxSog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
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/CAPncwvLw5yH2QpACrfHWsTW2J0ny6AmG3VU-JrYoD1X%2Bu_%2Bw%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)



No comments:
Post a Comment