Redirect_to Vs Render_component

Srividya Sharma wrote:

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
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

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.

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:

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.


I tried render_component, it seems to be slow.
Thanks a lot. I will give this a try.

Bharat Ruparel wrote: