从外部 ruby 脚本调用控制器的方法
我正在为我的 Rails 应用程序创建一个外部服务。它始终监听rabbitmq队列,并且它们的所有消息都应该重定向到rails控制器的某些方法。 我尝试过以下方法:
正确的方法是什么从另一个控制器操作运行一个控制器操作而不使用 HTTP 重定向?
http://www .misuse.org/science/2007/07/24/firing-rails-controller-actions-from-command-line-console/
第一个只允许我访问模型(无论如何,我想这一定是我想要的基础)。第二个...对我来说从来没有用过。最后一个方法在 Rails 3 上不起作用( ActionController::Integration 不存在)
,我认为如果我弄清楚 Rails 3 中如何处理会话,则仍然可以使用最后一种方法。无论如何,有人有以前尝试过类似的东西吗?任何建议将不胜感激。
I'm creating an external service of my rails app. This is always listening a rabbitmq queue and all their messages should be redirected to some methods of the rails controllers.
I've tried these approaches:
AMQP subscriber inside Rails app
http://www.misuse.org/science/2007/07/24/firing-rails-controller-actions-from-command-line-console/
The first one allowed me only to access the model (Anyway I suppose must be the base for what I want). The second one... never worked for me. And the last one doesn't works on rails 3 ( ActionController::Integration doesn't exists)
I think that the last approach still could be used if I figure out how the sessions are handled in rails 3. In any case, somebody had tried something similar before? Any suggestion will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不直接通过 HTTP 请求发送请求呢?您的控制器基本上通过 URL 使操作可见 - 只需向 URL 发出请求本质上与调用控制器代码相同,并且它使您的代码像软件服务/API 一样工作。如果您愿意,您甚至可以仅使用
curl
来执行此操作。否则,如果这两个文件位于同一台计算机/文件夹中,您可以尝试将一个控制器代码显式包含在另一个控制器代码中,但这似乎不是正确的方法。取决于您希望最终结果如何发挥作用。
Why not just send the request via an HTTP request? Your controller basically makes actions visible via URLs - simply making a request to the URL is essentially the same as calling the controller code, and it keeps your code working like a software service/API. You could even just use
curl
to do this if you want.Otherwise, if the two files are in the same machine/folder, you could try to explicitly include the one controller code in the other, but that seems like maybe not the way to go. Depends on how you want the end result to work.