Rails 2.3.14:如何序列化 ActionController::Request 对象?
我需要编写一些根据 Rails 2.3.14 控制器收到的请求对象类型执行操作的方法。但是,我不想启动整个应用程序,甚至不想启动控制器;我只想拥有这样一个对象的编组副本,以便我可以在 Rails 环境之外使用。
不幸的是,传递给控制器的 ActionController::Request
对象在其内部深处包含了本质上不可序列化的 Proc
对象。
有谁知道一种方法来序列化这些对象之一,以便我可以将其存储在数据文件中并在另一个脚本中重新创建它?我不想对 Proc
类进行猴子修补以提供 #marshal_dump
方法。
谢谢!
I need to write some methods that Do Things based on the kind of request object received by a Rails 2.3.14 controller. However, I don't want to fire up the entire application, nor even a controller; I'd like to have just a marshalled copy of such an object that I can work with outside of the Rails environment.
Unfortunately, the ActionController::Request
objects passed to controllers include, deep in their bowels, Proc
objects which are inherently unserialisable.
Does anyone know of a way to serialise one of these objects such that I can store it away in a data file and re-create it in another script? I would prefer not to monkey-patch the Proc
class to provide a #marshal_dump
method..
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诀窍是替换/删除不可序列化的对象(尤其是在 env-hash 中)。我在这个SO答案中实现了其中的一部分。我使用 Rails 3.2.13
request
对象稍微更新了我的方法。更新:噢,我刚刚看到您在询问 Rails
2.3.14
。我的视觉过滤器让我看到了3.2.14
。所以这仅适用于当前的 Rails 版本,抱歉。The trick is to replace/delete not serializable objects (especially in the env-hash). I implemented parts of it in this SO answer. I slightly updated my approach using a rails 3.2.13
request
object.Update: owww, I've just seen that you are asking vor Rails
2.3.14
. My visual filter let me see3.2.14
instead. So this only works for a current rails version, sorry.