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.
873a9db33e289b558e89c039629562f5?d=identicon&s=25 James Smith (jmdjmsmith)
on 2007-01-31 11: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?
6d57db44c5a4e0721cc7f78cf0ce308a?d=identicon&s=25 Stephen Bartholomew (steveb)
on 2007-01-31 12: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.