从外部 ruby​​ 脚本调用控制器的方法

发布于 2024-12-09 22:08:23 字数 874 浏览 4 评论 0原文

我正在为我的 Rails 应用程序创建一个外部服务。它始终监听rabbitmq队列,并且它们的所有消息都应该重定向到rails控制器的某些方法。 我尝试过以下方法:

Rails 应用程序内的 AMQP 订阅者

正确的方法是什么从另一个控制器操作运行一个控制器操作而不使用 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

What's the correct way to run one controller action from another controller action without an HTTP redirect?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅一夜美梦 2024-12-16 22:08:24

为什么不直接通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文