Passing parameters between controllers

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

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

Thanks Shai !! It worked :slight_smile:

~shishir

On Oct 21, 8:52 pm, Shai R. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs