# Passing data between controllers

**URL:** <https://www.ruby-forum.com/t/passing-data-between-controllers/109606>\
**Category:** Rails\
**Created:** [July 17, 2007, 8:16am UTC](https://www.ruby-forum.com/t/passing-data-between-controllers/109606 "2007-07-17T08:16:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prashanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/439d5e/32.png) [@prashanth](https://www.ruby-forum.com/u/prashanth)\
**Post date:** [July 17, 2007, 8:16am UTC](https://www.ruby-forum.com/t/passing-data-between-controllers/109606/1 "2007-07-17T08:16:00Z")

</div>

hi,

```
 i want to pass the data between the controller,

```

Eg:

def a  
num = 10  
print num  
end

def b  
print num  
end

if i load the b i want to get 10, how to do this? I tried to return  
the num that dint work. how to do this?

–  
regards,

|Prashanth|

> **[PengobatanHerbalAndalan](http://munichlinux.blogspot.com)**
>
> Lirik lagu terbaru Indonesia dan lagu barat. Tangga lagu terbaru di blog lirik lagu..

---

<div class="post-metadata">

**Author:** ![prashanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/439d5e/32.png) [@prashanth](https://www.ruby-forum.com/u/prashanth)\
**Post date:** [July 17, 2007, 10:44am UTC](https://www.ruby-forum.com/t/passing-data-between-controllers/109606/2 "2007-07-17T10:44:52Z")

</div>

…there may be simpler way, but the first most appropriate thing that  
pops into my mind is creating a module and including the module in both  
controllers as such:

====== controllers/one\_controller.rb ========

class OneController  
include MyModule

def a  
print\_num  
end

end

====== controllers/two\_controller.rb ========

class TwoController  
include MyModule

def b  
print\_num  
end

end

====== lib/my\_module.rb ========

class MyModule

def print\_num  
n=10  
print n  
end

both actions return ‘10’:

[domain.com/one/a](http://domain.com/one/a)  
[domain.com/two/b](http://domain.com/two/b)

hth 🙂
