Forum: Ruby on Rails Passing objects??

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
James S. (Guest)
on 2007-01-31 12:55

I was wondering if it was possible to pass objects between methods in
the controllers - or whether you can only pass strings??


def method_one
@object = Model.find(params[:id)
redirect_to :action => "method_to", :object => @object

def method_two
@object = params[:object]

The question is basically - can i access the object in method_two?
Or do i have to just pass the model id to method two and do another
query to find the model object?

Which is best practice?
Stephen B. (Guest)
on 2007-01-31 13:04
(Received via mailing list)
> Which is best practice?
Pass the model id and find it in the next action.

You could store the object in session (session[:object] = @object),
but generally it's best to keep the session lightweight.

This topic is locked and can not be replied to.