redirect with parameters
Posted by Jonathan | Posted in rhomobile | Posted on 07-10-2011
0
I posted a while back about passing parameters between views from within a link.
Today I’ll post this code to remind myself how to do that from within a redirect.
Sometimes in your view or controller, you might call a method to do something – say store something in the database and pop up a message, and you might need to redirect to a new view/method after that. Well sometimes you need to get some parameter(s) to that new page as well. If you search the system-api-samples project Rhomobile has – you won’t find this in there. Ok, you might, I didn’t.
I had a ‘duh’ moment when I got this to work, because its pretty dang near identical to passing parameters in a link.
Here it is in all its glory :
Where list_details is the destination method and we’re passing session_id with the variable @session_id
redirect :action => :list_details, :query => {:session_id => @session_id}
If you had more parameters, you’d separate them with a comma like this -
:query => {:session_id => @session_id, :session_title => @my_title, :message => 'it worked'}
Easy, right?
theCodeDog
