# Passing parameters between controllers

**URL:** <https://www.ruby-forum.com/t/passing-parameters-between-controllers/117837>\
**Category:** Rails\
**Created:** [October 21, 2007, 9:17am UTC](https://www.ruby-forum.com/t/passing-parameters-between-controllers/117837 "2007-10-21T09:17:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [October 21, 2007, 9:17am UTC](https://www.ruby-forum.com/t/passing-parameters-between-controllers/117837/1 "2007-10-21T09:17:24Z")

</div>

Hi,

I am trying to pass some parameters from one controller method to a  
method in a different controller , using the rediret\_to method. My  
code is something like this

controllerA

def method1  
id =(params[‘user\_name’])  
redirect\_to({:controller =\> “controllerB”, :action =\>  
“method2”}, :user=\>id)  
end

controllerB  
def method2 user  
@user=user  
end

However this doesn’t seem to be working , because in view when I use \<  
%= @user%\> to display the user name , I get the error : wrong number  
of arguments (0 for 1)

Any clue , where am going wrong.

TIA  
~shishir

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [October 21, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/passing-parameters-between-controllers/117837/2 "2007-10-21T17:52:48Z")

</div>

# controllerA

def method1  
id =(params[‘user\_name’])  
redirect\_to({:controller =\> “controllerB”, :action =\>  
“method2”, :user=\>id } ) # put the :user INSIDE the path hash.  
end

# controllerB

def method2 user # DONT NEED THIS  
def method2 # without the user parameter  
@user=params[‘user’] #–\> the parameter is passed automatically via the  
params hash; no need to define the parameter in the def clause.  
end

enjoy

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [October 21, 2007, 8:59pm UTC](https://www.ruby-forum.com/t/passing-parameters-between-controllers/117837/3 "2007-10-21T20:59:30Z")

</div>

Thanks Shai !! It worked 🙂

~shishir

On Oct 21, 8:52 pm, Shai R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
