# How to preserve the value from the other action controller

**URL:** <https://www.ruby-forum.com/t/how-to-preserve-the-value-from-the-other-action-controller/185399>\
**Category:** Rails\
**Created:** [March 19, 2010, 9:13am UTC](https://www.ruby-forum.com/t/how-to-preserve-the-value-from-the-other-action-controller/185399 "2010-03-19T09:13:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![soesan01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@soesan01](https://www.ruby-forum.com/u/soesan01)\
**Post date:** [March 19, 2010, 9:13am UTC](https://www.ruby-forum.com/t/how-to-preserve-the-value-from-the-other-action-controller/185399/1 "2010-03-19T09:13:32Z")

</div>

Hi,

Anyone knows how to preserve the value from the previous action  
controller?

For example,

- I have 2 controllers: foo\_one and foo\_two.
- on action foo\_one, I have variable @my\_value
- How I can keep the value of @my\_value so I can use it on the second  
controller foo\_two

def foo\_one  
@my\_value = params[:preserve\_value]  
end

def foo\_two  
puts @preserve\_value  
end

I don’t want to use session or global variable. any suggestion?

Yudi S.

---

<div class="post-metadata">

**Author:** ![soesan01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@soesan01](https://www.ruby-forum.com/u/soesan01)\
**Post date:** [March 19, 2010, 10:38am UTC](https://www.ruby-forum.com/t/how-to-preserve-the-value-from-the-other-action-controller/185399/2 "2010-03-19T10:38:24Z")

</div>

On 19 March 2010 08:12, Yudi S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> def foo\_one  
> @my\_value = params[:preserve\_value]  
> end
> 
> def foo\_two  
> puts @preserve\_value  
> end
> 
> I don’t want to use session or global variable. any suggestion?

Assuming foo\_one calls foo\_too (so it’s in the same request - hence your  
global variable mention), then you could define an attr\_accessor on  
foo\_two’s controller and set it from there.

But, if it’s not being executed in the same request, session (be it  
Rails  
session, database or memcached) is the only way (or flash so it’s  
automatically removed after the next request).

Cheers,

Andy

---

<div class="post-metadata">

**Author:** ![soesan01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@soesan01](https://www.ruby-forum.com/u/soesan01)\
**Post date:** [March 19, 2010, 11:11am UTC](https://www.ruby-forum.com/t/how-to-preserve-the-value-from-the-other-action-controller/185399/3 "2010-03-19T11:11:46Z")

</div>

Thanks for your reply.  
I will do research on memcached

Yudi S.
