# How to Pass a Large Array from one Action to Another

**URL:** <https://www.ruby-forum.com/t/how-to-pass-a-large-array-from-one-action-to-another/152152>\
**Category:** Rails\
**Created:** [October 30, 2008, 4:19pm UTC](https://www.ruby-forum.com/t/how-to-pass-a-large-array-from-one-action-to-another/152152 "2008-10-30T16:19:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [October 30, 2008, 4:19pm UTC](https://www.ruby-forum.com/t/how-to-pass-a-large-array-from-one-action-to-another/152152/1 "2008-10-30T16:19:33Z")

</div>

Good morning everybody, how are you?

Okay, this should be easy. I am generating a large array in one action,  
and I want to pass this array to another action when the user pushes a  
button.

@problems is a large array (about 2,000 items) that I need to pass to  
the action “buy\_cards”. What is the best way to do this? I’m pretty  
sure it’s too big for a session, and I don’t want to store it in DB,  
since I just need it temporarily:

\<%= button\_to “Buy Cars”, :action =\> :buy\_cars, :car\_id =\> @file\_id,  
:problems =\> @problems %\>

Anyone know a good way to pass a large array from one action to another?

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [October 30, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/how-to-pass-a-large-array-from-one-action-to-another/152152/2 "2008-10-30T16:43:10Z")

</div>

How about putting a serialized version of it as an attachment using a  
multipart-form? As long as you’re using a POST in your form action there  
shouldn’t be any set limit on the size of data that you’re posting.

@problems.to\_yaml (or @problems.to\_json) should give you a textual  
format. Then in the receiving action de-serialize the yaml (or json).

Joe P. wrote:

> Good morning everybody, how are you?
> 
> Okay, this should be easy. I am generating a large array in one action,  
> and I want to pass this array to another action when the user pushes a  
> button.
> 
> @problems is a large array (about 2,000 items) that I need to pass to  
> the action “buy\_cards”. What is the best way to do this? I’m pretty  
> sure it’s too big for a session, and I don’t want to store it in DB,  
> since I just need it temporarily:
> 
> \<%= button\_to “Buy Cars”, :action =\> :buy\_cars, :car\_id =\> @file\_id,  
> :problems =\> @problems %\>
> 
> Anyone know a good way to pass a large array from one action to another?

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [October 31, 2008, 2:47am UTC](https://www.ruby-forum.com/t/how-to-pass-a-large-array-from-one-action-to-another/152152/3 "2008-10-31T02:47:04Z")

</div>

Joe P. wrote:

> Good morning everybody, how are you?
> 
> Okay, this should be easy. I am generating a large array in one action,  
> and I want to pass this array to another action when the user pushes a  
> button.
> 
> Anyone know a good way to pass a large array from one action to another?

I would recommend serializing it into a temp file on the server and  
reading it back out in the other action. You should be able to serialize  
it with “to\_json”, and just write it to a file. Then read it back into  
an array in the other action. Name the temp file relative to the user  
so you don’t have to worry about a name collision, and then pass the  
path to the temp file in the session.

HTH,  
jp
