在 Rails 上使用龙卷风和 ruby
我正在构建一个简单的 Rails 应用程序,并正在使用 Tornado 来实现该应用程序的一些实时部分。到目前为止,我的经验仅限于使用单个 Web 框架来满足我的所有需求。我第一次使用两个不同的网络框架。
我对 Rails 和 Tornado 如何协同工作感到困惑。所以,我有一个rails服务器和一个tornado服务器在不同的端口上运行。它们都将通过路由配置处理自己的请求。后端说得有道理。我感到困惑的部分是前端集成。假设我有一个页面,显示我的登录/注销状态以及来自 Twitter 的实时推文流,每条推文旁边都有一个删除按钮。我的 Rails 服务器知道已登录/注销状态。这些推文由我的 Tornado 服务器处理。如何在前端整合来自两台服务器的两条信息?
我是否从 Rails 控制器调用 Tornado 服务器并处理 JSON?如果是这样,我不会失去事物的实时性吗?
我是否在 .erb 模板中使用调用 Tornado 服务器的 iframe?如果是这样,如何将 iframe 与每条推文旁边的删除按钮集成?
提前致谢!
I am building a simple rails application and am working with Tornado for some of the real-time parts of the app. My experience thus far as been limited to using a single web framework for all my needs. First time I am using two different web frameworks.
I am confused as to how rails and tornado can work together. So, I have a rails server and a tornado server running on different ports. They both will handle their own requests via their routing configuration. The backend make sense. The part I am confused about is the front-end integration. Let us say I have a page which shows my logged in/logged out status along with real-time stream of tweets from Twitter with a delete button next to each tweet. The logged/logged out status is known to my rails server. The tweets are being handled by my Tornado server. How do I integrate both pieces of information from the two servers in the front-end?
Do I call the Tornado server from my rails controller and process the JSON? If so, won't I lose the real-time aspect of things?
Do I use an iframe in my .erb template which calls the Tornado server? If so, how do I integrate the iframe with the delete buttons next to each tweet?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会在两个不同的端口(不是端口 80)上运行tornado 和rails。我将在端口 80 上运行 nginx。我将配置 nginx 来代理 /realtime 名称空间中的tornado 以及其他任何地方的rails。现在你的客户端说 JS 代码只是向服务器询问不同的 URL,而它永远不需要知道哪个是哪个。
I would run tornado and rails on two different ports (not port 80). I would run nginx on port 80. I would configure nginx to proxy for tornado in the /realtime name space and to rails everywhere else. Now your client said JS code just asks the server for different URLs and it never has to know which one is which.
您应该在 Rails 应用程序页面上通过 Javascript 访问 Tornado 服务器。因此,是客户端的浏览器访问 Tornado 服务器,而不是 Rails 服务器。
You should hit the Tornado server from Javascript on the page of your Rails app. So it's the client's browser hitting the Tornado server, not your Rails server.