# How to pass a value from one action to another?

**URL:** <https://www.ruby-forum.com/t/how-to-pass-a-value-from-one-action-to-another/134284>\
**Category:** Rails\
**Created:** [April 9, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/how-to-pass-a-value-from-one-action-to-another/134284 "2008-04-09T14:42:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [April 9, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/how-to-pass-a-value-from-one-action-to-another/134284/1 "2008-04-09T14:42:33Z")

</div>

Dear group,

What are the most elegant ways in Rails to pass the VARIABLE’s value:

- from action A
- to action B?

Until now, I’ve been doing this like this (but I’m sure there are other  
ways):

1. In action A: redirect\_to :action =\> ‘B’, :id =\> VARIABLE
2. In action B: variable = params[:id]

OR:

1. In action A: display a form (form\_for :myForm") with a hidden field +  
pass the hidden field a value
2. In action B: value = params[:myForm][:myHiddenField]

What are the most elegant for passing values in the most direct way?  
Is it possible to easily pass values that are not visible to the user?

Thanks a lot!  
Tom

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [April 9, 2008, 3:26pm UTC](https://www.ruby-forum.com/t/how-to-pass-a-value-from-one-action-to-another/134284/2 "2008-04-09T15:26:21Z")

</div>

Sorry, me stupid…

-\> You pass the value to the session and retrieve it from the session as  
soon as needed…

In case there’s something even better, you’re still welcome!
