# How to pass data across the different controllers

**URL:** <https://www.ruby-forum.com/t/how-to-pass-data-across-the-different-controllers/168409>\
**Category:** Rails\
**Created:** [May 20, 2009, 3:56pm UTC](https://www.ruby-forum.com/t/how-to-pass-data-across-the-different-controllers/168409 "2009-05-20T15:56:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vipin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/edb3f5/32.png) [@Vipin](https://www.ruby-forum.com/u/Vipin)\
**Post date:** [May 20, 2009, 3:56pm UTC](https://www.ruby-forum.com/t/how-to-pass-data-across-the-different-controllers/168409/1 "2009-05-20T15:56:51Z")

</div>

I have made three scaffold generated controllers in my project by  
following three commands

ruby script/generate scaffold amain a:integer  
ruby script/generate scaffold bmain b:integer  
ruby script/generate scaffold cmain c:integer

I want to take three different inputs( a,b,c) on three different pages  
and then on the third page once a user clicks the button “Calculate” a  
value based on following equation has to be generated.

value = a + b_x1 + c_x2

here,  
x1 is set on the page where input “a” is set  
and x2 is set on the page where input “b” is set

x1 and x2 are virtual attributes and hence do not exist in any of the  
data models. Value of these coefficients is not constant and in fact  
depends on several dynamic factor such as the date and time when a/b  
was set.

I want to know how to pass on the values of “x1” and “x2” from one  
controller to another. These attributes are not the part of model of  
“a” or model of “b”. I can not keep them in models.

Thanks  
vipin

---

<div class="post-metadata">

**Author:** ![Vipin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/edb3f5/32.png) [@Vipin](https://www.ruby-forum.com/u/Vipin)\
**Post date:** [May 20, 2009, 8:36pm UTC](https://www.ruby-forum.com/t/how-to-pass-data-across-the-different-controllers/168409/2 "2009-05-20T20:36:18Z")

</div>

You can always pass the values as hidden fields… your data isn’t going  
directly from controller to controller. There are views in between, so  
you need a way to ship the data via the views. If you don’t want to see  
the values on the pages, you can use hidden fields to pass along the  
data.

---

<div class="post-metadata">

**Author:** ![Vipin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/edb3f5/32.png) [@Vipin](https://www.ruby-forum.com/u/Vipin)\
**Post date:** [May 21, 2009, 4:35am UTC](https://www.ruby-forum.com/t/how-to-pass-data-across-the-different-controllers/168409/3 "2009-05-21T04:35:03Z")

</div>

On May 20, 11:36 pm, Ar Chron [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## You can always pass the values as hidden fields… your data isn’t going directly from controller to controller. There are views in between, so you need a way to ship the data via the views. If you don’t want to see the values on the pages, you can use hidden fields to pass along the data.
> 
> Posted viahttp://www.ruby-forum.com/.

you mean to say in view there should be some fields which will be set  
in controller but will be invisible to the user.  
Then in this case, will the values be accessed through param[] table.  
Can you please give a small example or some pointer to study about  
this topic. if possible

vipin
