Rails Learner
2010-Jun-22 19:03 UTC
Pass instance variable from one method to another controller
Hi Everybody! I m back. I have a non-model form (I am using active_record_no_table gem for validations). When the user fills that form and submits it, I want to process the form and then display it back to the user just like the "show" method in a scaffold. Now, since this is a non-model form, I need to pass the instance variable from "create" method to "show" method. I know that rather than redirecting to show method, I can display data back to the user using a partial and passing a locals hash to the partial. But I don''t want to do this. The reason is there is a link on the "show" view that allows the user to print the show view in PDF format and I want to do the same with the link...passing the local variable to the show action. How can I do this? Please advise? Many Thanks! -- Posted via http://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jun-22 20:10 UTC
Re: Pass instance variable from one method to another controller
Rails Learner wrote:> Hi Everybody! > > I m back. > I have a non-model form (I am using active_record_no_table gem for > validations). When the user fills that form and submits it, I want to > process the form and then display it back to the user just like the > "show" method in a scaffold. > > Now, since this is a non-model form, I need to pass the instance > variable from "create" method to "show" method. > > I know that rather than redirecting to show method, I can display data > back to the user using a partial and passing a locals hash to the > partial. > But I don''t want to do this. The reason is there is a link on the "show" > view that allows the user to print the show view in PDF format and I > want to do the same with the link...passing the local variable to the > show action. > > How can I do this? >Put in a link_to parameter. Remember that link_to can take more options than :controller and :action.> Please advise? > > Many Thanks!Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rails Learner
2010-Jun-22 20:24 UTC
Re: Pass instance variable from one method to another controller
Hi Marnen, How can I pass the the whole object in link_to? For instance, if I have a child object with first_name and last_name as attributes, then I need to pass the child object as a hash. Right now, what is working for me is this: <%= link_to ''Create PDF'', { :controller => ''children'', :action => ''show'', :format => :pdf, :first_name => @child.first_name, :last_name => @child.last_name } %> And, I want to do something like this (but it''s not working): <%= link_to ''Create PDF'', { :controller => ''children'', :action => ''show'', :format => :pdf, :child => @child } %> -- Posted via http://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jun-22 20:38 UTC
Re: Pass instance variable from one method to another controller
Rails Learner wrote:> Hi Marnen, > > How can I pass the the whole object in link_to?You can''t.> > For instance, if I have a child object with first_name and last_name as > attributes, then I need to pass the child object as a hash.No. Pass them as two separate parameters (as I guess you''re currently doing), munge them together into one string (not recommended), or pass an object ID if you can query the DB for it.> > Right now, what is working for me is this: > <%= link_to ''Create PDF'', { :controller => ''children'', :action => > ''show'', :format => :pdf, :first_name => @child.first_name, :last_name => > @child.last_name } %> > > And, I want to do something like this (but it''s not working): > <%= link_to ''Create PDF'', { :controller => ''children'', :action => > ''show'', :format => :pdf, :child => @child } %>-- Posted via http://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rails Learner
2010-Jun-23 15:20 UTC
Re: Pass instance variable from one method to another controller
Hi Marnen, Thanks for confirming that. Many Thanks! -- Posted via http://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.