Hi,
I am developing a Rails app where I need to pass an object around between views. I am doing this by sending each view the object_id, and then doing
@theObject = ObjectSpace._id2ref(params[:objid])
This is a really bad idea (and of course were you ever to have more
than one mongrel then the 2 requests could be server by completely
separate processes, which means that it would be completely impossible
for this to ever work).
There are two problems with this: One, it's not very elegant. Is
there a better way? Two, I get an intermittent error, "RangeError : 0xfooba4 is recycled object". I *suspect* this happens because my object is
getting garbage collected between views. Since it is an instance member of my controller object (I've also experimented with making it a class member), I feel this ought not to happen, but there it is.
A given instance of controller only lasts for one request. I suspect
you're running in dev mode, so classes are also reloaded after each
request.
Can anyone suggest a better method for persisting my object so all my views have access to it, and it doesn't get garbage
collected?
Serialize it and store the data in the db, memcached or even the
session.
Fred