开发者

Call a controller's method from an external ruby script

开发者 https://www.devze.com 2023-04-13 05:20 出处:网络
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'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 wi开发者_如何学Gothout 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号