Lance Klusener
2009-Jan-07 21:01 UTC
Passing data from action of cntrlr 1 to action of cntrlr 2
The question is about passing data from action of one controller to action of another controller. Inside the new_patient_controller i have the following code when the button "next" is clicked def create_visit (created_patient) redirect_to(:controller=>"patient_visit",:action=>"index",:created_patient=>created_patient) end This is suppose to call the index view of the "patient_visit" controller . Now the "patient_visit" controller has the following form 1. <% form_for :patient_visit , :url => { :action => :save_patient_visit } do |form| %> 2. 3. <p> 4. <%= label :patient_visit , :complaints , "Complaints:" %> 5. <%= form.text_area :complaints , :size => 20 %> 6. </p> 7. 8. <p> 9. <%= label :patient_visit , :systemic_history , "Systemic History:" %> 10. <%= form.text_field :systemic_history , :size => 40 %> 11. </p> 12. 13. <p> 14. <%= label :patient_visit , :opthal_history , "Opthal History:" %> 15. <%= form.text_field :opthal_history , :size => 40 %> 16. </p> 17. 18. <%= submit_tag "next" , :class => "submit" %> 19. 20. <%end%> Because of this the params which originally had the value of "created_patient" now gets overwritten with the new params which has the value of ":patient_visit" . I need the created_patient value , cause i need to attach the patient_visit database entry to the created_patient. ( since one patient has many visits ) -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mukund
2009-Jan-08 09:29 UTC
Re: Passing data from action of cntrlr 1 to action of cntrlr 2
Use the flash object to transfer data between controller actions. Regards, Mukund On Jan 8, 2:01 am, Lance Klusener <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> The question is about passing data from action of one controller to > action of another controller. > > Inside the new_patient_controller i have the following code when the > button "next" is clicked > > def create_visit (created_patient) > redirect_to(:controller=>"patient_visit",:action=>"index",:created_patient=>created_patient) > end > > This is suppose to call the index view of the "patient_visit" controller > . > > Now the "patient_visit" controller has the following form > > 1. <% form_for :patient_visit , :url => { :action => > :save_patient_visit } do |form| %> > 2. > 3. <p> > 4. <%= label :patient_visit , :complaints , "Complaints:" %> > 5. <%= form.text_area :complaints , :size => 20 %> > 6. </p> > 7. > 8. <p> > 9. <%= label :patient_visit , :systemic_history , "Systemic > History:" %> > 10. <%= form.text_field :systemic_history , :size => 40 %> > 11. </p> > 12. > 13. <p> > 14. <%= label :patient_visit , :opthal_history , "Opthal > History:" %> > 15. <%= form.text_field :opthal_history , :size => 40 %> > 16. </p> > 17. > 18. <%= submit_tag "next" , :class => "submit" %> > 19. > 20. <%end%> > > Because of this the params which originally had the value of > "created_patient" now gets overwritten with the new params which has the > value of ":patient_visit" . > > I need the created_patient value , cause i need to attach the > patient_visit database entry to the created_patient. ( since one patient > has many visits ) > -- > Posted viahttp://www.ruby-forum.com.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Jan., 10:29, Mukund <marut...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Use the flash object to transfer data between controller actions.... or just add , :created_patient => params[:created_patient] to your form (where you specify the action that is called) so your param ain''t lost. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Jan-08 10:15 UTC
Re: Passing data from action of cntrlr 1 to action of cntrlr 2
you can transmit values between controllers in the following ways: - parameters to request (if not too long and not compromising security) - session (recommended to store id, not objects) On Jan 8, 10:52 am, MaD <mayer.domi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 8 Jan., 10:29, Mukund <marut...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > Use the flash object to transfer data between controller actions. > > ... or just add > > , :created_patient => params[:created_patient] > > to your form (where you specify the action that is called) so your > param ain''t lost.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pardee, Roy
2009-Jan-08 13:32 UTC
Re: Passing data from action of cntrlr 1 to action of cntrlr 2
Try something like: def create_visit(for_patient) # This populates patient_visit.patient_id w/the proper id value patient_visit = for_patient.visits.new # Note that I''ve changed the action from index to new--that''s # the convention for actions that create new objects. redirect_to(:controller=>"patient_visit", :action=>"new") end And then in your view, you add: <%= form.hidden_field(:patient_id) %> Anyplace inside your form_for block. That should get you a params[:patient_visit] from which you can create a visit for a specific patient. HTH, -Roy -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Lance Klusener Sent: Wednesday, January 07, 2009 1:01 PM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Passing data from action of cntrlr 1 to action of cntrlr 2 The question is about passing data from action of one controller to action of another controller. Inside the new_patient_controller i have the following code when the button "next" is clicked def create_visit (created_patient) redirect_to(:controller=>"patient_visit",:action=>"index",:created_patient=>created_patient) end This is suppose to call the index view of the "patient_visit" controller . Now the "patient_visit" controller has the following form 1. <% form_for :patient_visit , :url => { :action => :save_patient_visit } do |form| %> 2. 3. <p> 4. <%= label :patient_visit , :complaints , "Complaints:" %> 5. <%= form.text_area :complaints , :size => 20 %> 6. </p> 7. 8. <p> 9. <%= label :patient_visit , :systemic_history , "Systemic History:" %> 10. <%= form.text_field :systemic_history , :size => 40 %> 11. </p> 12. 13. <p> 14. <%= label :patient_visit , :opthal_history , "Opthal History:" %> 15. <%= form.text_field :opthal_history , :size => 40 %> 16. </p> 17. 18. <%= submit_tag "next" , :class => "submit" %> 19. 20. <%end%> Because of this the params which originally had the value of "created_patient" now gets overwritten with the new params which has the value of ":patient_visit" . I need the created_patient value , cause i need to attach the patient_visit database entry to the created_patient. ( since one patient has many visits ) -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---