Forum: Ruby on Rails Passing objects??

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

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

example:

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

def method_two
@object = params[:object]
end

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.

Steve
This topic is locked and can not be replied to.