Passing a model as a parameter

Here’s the situation:

I need to do a redirect from a controller and I want to pass an object
to the redirect but I can’t figure out how to pass it without it being
turned into an unreadable string.

I’m doing this:

redirect_to :controller => ‘pizza’, :task => params[:task]

but it is passing this in the request:

Parameters: {“task”=>“titlesfdspriority1contentsdfuser_id2”}

Any way I can get it back to looking like the original parameter:

“task”=>{“title”=>“fds”, “priority”=>“1”, “content”=>“d”,
“user_id”=>“2”}

???

Thanks for your help

chris young wrote:

Any way I can get it back to looking like the original parameter:

“task”=>{“title”=>“fds”, “priority”=>“1”, “content”=>“d”,
“user_id”=>“2”}

How bout…

redirect_to :controller => ‘pizza’, task[title] =>
params[:task][:title], task[priority] => params[:task][:priority], etc,
etc

no clue if that’ll work, but try it and see.

Dave

redirect_to :controller => ‘pizza’, :task => params[:task]

but it is passing this in the request:

Parameters: {“task”=>“titlesfdspriority1contentsdfuser_id2”}

Any way I can get it back to looking like the original parameter:

well… for only four parameters maybe you could just pass the four of
them directly. If not another common approach is to pass just the id and
hit the db again (if you are lucky the last find will be cached, so db
will not be even hit).

anyway, for anytime you want to pass something like this you can always
serialize. The ruby class for that is Marshal. Not total recall here,
but I’d say i saw recently a ticket on the dev site about models not
deserializing the relationships properly when using Marshal (just in
case).

regards,

javier ramirez

Estamos de estreno… si necesitas llevar el control de tus gastos
visita http://www.gastosgem.com !!Es gratis!!

On 3/19/07, javier ramirez [email protected] wrote:

well… for only four parameters maybe you could just pass the four of
them directly. If not another common approach is to pass just the id and
hit the db again (if you are lucky the last find will be cached, so db
will not be even hit).

anyway, for anytime you want to pass something like this you can always
serialize. The ruby class for that is Marshal. Not total recall here,
but I’d say i saw recently a ticket on the dev site about models not
deserializing the relationships properly when using Marshal (just in case).

You could also store it in the session.

Isak

Okay, I’m going to go with passing individual parameters. Man, I wish i
hadn’t wasted an hour on this!

Thanks Javier and Isak!

javier ramirez wrote:

redirect_to :controller => ‘pizza’, :task => params[:task]

but it is passing this in the request:

Parameters: {“task”=>“titlesfdspriority1contentsdfuser_id2”}

Any way I can get it back to looking like the original parameter:

well… for only four parameters maybe you could just pass the four of
them directly. If not another common approach is to pass just the id and
hit the db again (if you are lucky the last find will be cached, so db
will not be even hit).

anyway, for anytime you want to pass something like this you can always
serialize. The ruby class for that is Marshal. Not total recall here,
but I’d say i saw recently a ticket on the dev site about models not
deserializing the relationships properly when using Marshal (just in
case).

regards,

javier ramirez

Estamos de estreno… si necesitas llevar el control de tus gastos
visita http://www.gastosgem.com !!Es gratis!!