Hello I am using Rails 2.2.2. Here is my problem: I have a controller action which will receive several parameters, validate them, process them and create a new set of parameters out of them. Then, this controller should delegate the task to another controller action based on some values and pass these processed parameters to it. I have stored the processed parameters in a hash. (there are many of them) I could only see two options to achieve this: 1. Use redirect_to and pass each parameter as a string. 2. Use render_component and pass the parameters as a hash. I have seen that render_component is not recommended in most cases. Is it recommended solution for this case? I think render_component slows down the request also. Which option is right for me? Are there any other ways to achieve this? Please guide me. Thanks in advance. -- 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-/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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Srividya Sharma wrote:> Hello > I am using Rails 2.2.2. > Here is my problem: > I have a controller action which will receive several parameters, > validate them, process them and create a new set of parameters out of > them. > Then, this controller should delegate the task to another controller > action based on some values and pass these processed parameters to it. I > have stored the processed parameters in a hash. (there are many of them) > > I could only see two options to achieve this: > 1. Use redirect_to and pass each parameter as a string. > 2. Use render_component and pass the parameters as a hash. > > I have seen that render_component is not recommended in most cases. Is > it recommended solution for this case? I think render_component slows > down the request also. > Which option is right for me? > Are there any other ways to achieve this? Please guide me.If you don''t want the browser url to change, you can just call the other action like a method, passing the parameters in either an instance variable or a method parameter (that''s default nil to allow it to be called externally). Or are you messing with params directly? This is assuming the other method is in the same controller. If it isn''t, you''ll have to make the other method available within the first controller, either through inheritance or mix-ins. -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nice to see a response. The other method is in another controller. And the other method needs to use send_data. (basically write a response) So I cannot use a simple class, include that class in the first controller. since the other method has to write out a response, it needs to be in another controller.(I hope I am right about this) In the first controller, the request parameters are processed and these processed parameters need to be passed to the other method in the other controller. Mark Reginald James wrote:> Srividya Sharma wrote: >> I could only see two options to achieve this: >> 1. Use redirect_to and pass each parameter as a string. >> 2. Use render_component and pass the parameters as a hash. >> >> I have seen that render_component is not recommended in most cases. Is >> it recommended solution for this case? I think render_component slows >> down the request also. >> Which option is right for me? >> Are there any other ways to achieve this? Please guide me. > > If you don''t want the browser url to change, you can just call > the other action like a method, passing the parameters in either > an instance variable or a method parameter (that''s default nil > to allow it to be called externally). Or are you messing with > params directly? > > This is assuming the other method is in the same controller. > If it isn''t, you''ll have to make the other method available > within the first controller, either through inheritance or > mix-ins. > > -- > Rails Wheels - Find Plugins, List & Sell Plugins - > http://railswheels.com-- 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-/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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Srividya, The way I have been doing this rather quick and dirty but it works. Basically, you want to communicate between two HTTP requests. One of the most useful facilities in Rails is flash which is a special member of the session hash. It is special in the sense that it is temporary. By default, it will retain the values stored in it across two request and then it discards them automatically. Easy solution, just stuff the hash in the flash which itself is a hash anyway and retrieve it in any action that you desire. It has worked very well for me. Bharat --~--~---------~--~----~------------~-------~--~----~ 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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
So, I should use redirect_to and use flash for passing the hash. Can you give me code snippet? Thanks a lot. Bharat Ruparel wrote:> Srividya, > The way I have been doing this rather quick and dirty but it works. > Basically, you want to communicate between two HTTP requests. One of > the most useful facilities in Rails is flash which is a special member > of the session hash. It is special in the sense that it is > temporary. By default, it will retain the values stored in it across > two request and then it discards them automatically. Easy solution, > just stuff the hash in the flash which itself is a hash anyway and > retrieve it in any action that you desire. It has worked very well > for me. > Bharat-- 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-/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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
1. place where you want to save your hash: flash[:my_hash] = some_hash 2. place where you want retrieve your saved hash in flash: this_hash = flash[:my_hash] Now this_hash has your saved data. Bharat -- 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-/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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I tried render_component, it seems to be slow. Thanks a lot. I will give this a try. Bharat Ruparel wrote:> 1. place where you want to save your hash: > > flash[:my_hash] = some_hash > > 2. place where you want retrieve your saved hash in flash: > > this_hash = flash[:my_hash] > > Now this_hash has your saved data. > > Bharat-- 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-/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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I tried using the flash message, but the data that I need to pass is huge. so, I get a cookie overflow error. This technique did not work out for me. Is there anything else I could use? I just recalled that render_component is deprecated in 2.2.2 and a plug-in has to be used to get the same functionality. Is there any way out? Srividya Sharma wrote:> I tried render_component, it seems to be slow. > Thanks a lot. I will give this a try. > > Bharat Ruparel wrote: >> 1. place where you want to save your hash: >> >> flash[:my_hash] = some_hash >> >> 2. place where you want retrieve your saved hash in flash: >> >> this_hash = flash[:my_hash] >> >> Now this_hash has your saved data. >> >> Bharat-- 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-/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 http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---