Ruby on Rails 和 Node.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3527482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:40:09  来源:igfitidea点击:

Ruby on rails and Node.js

ruby-on-railsnode.jsrailstutorial.org

提问by user425891

I am wondering how to integrate node.js on a rails app (for learning purpose).

我想知道如何将 node.js 集成到 Rails 应用程序上(用于学习目的)。

Based on Michael Hartl tutorial (http://railstutorial.org/) I realized a basic twitter clone with rails and want to get user microposts in real-time without the use of comet or juggernaut. (the application is hosted on heroku)

基于 Michael Hartl 教程 ( http://railstutorial.org/),我实现了一个带有 rails 的基本 twitter 克隆,并希望在不使用彗星或主宰的情况下实时获取用户微博。(该应用程序托管在 heroku 上)

For the moment, I only see example with node.js frameworks (http://howtonode.org/grasshopper-shoutbox) but nothing merged with a ruby on rails app. I would be very thankful if someone knows a good tutorial or give me some points to start in order to accomplish this.

目前,我只看到 node.js 框架的示例(http://howtonode.org/grasshopper-shoutbox),但没有与 ruby​​ on rails 应用程序合并。如果有人知道一个好的教程或给我一些要点以开始实现这一点,我将非常感激。

Thanks!

谢谢!

采纳答案by Andy Atkinson

As Shripad said, I'd consider trying to build your app with Node by itself. Geddywill feel familiar (getting started anyway) if you have experience with Rails. Note: I do not have experience on a real world app with Geddy, but it is the best Rails-like framework I've seen so far. For persistence you can use SQLite, PostgreSQL or CouchDB, just like you would with Rails. I thought about how to communicate between a Rails app and Node without any intermediary. In our work project we're using Redis as an intermediary between Rails and Node. Rails publishes messages to Redis, Node pulls messages from Redis. I could not find a good way or example projects to avoid the middle communication layer on a personal project, so I went with the same setup. The good news is Node Redis modules are written and once you get everything installed, it is easy to test out pushing messages back and forth.

正如 Shripad 所说,我会考虑尝试使用 Node 本身来构建您的应用程序。格迪如果您有使用 Rails 的经验,您会觉得很熟悉(无论如何都是入门)。注意:我没有使用 Geddy 开发真实世界的应用程序的经验,但它是迄今为止我见过的最好的类似 Rails 的框架。对于持久性,您可以使用 SQLite、PostgreSQL 或 CouchDB,就像使用 Rails 一样。我想过如何在没有任何中介的情况下在 Rails 应用程序和 Node 之间进行通信。在我们的工作项目中,我们使用 Redis 作为 Rails 和 Node 之间的中介。Rails 向 Redis 发布消息,Node 从 Redis 拉取消息。我找不到一个好的方法或示例项目来避免个人项目中的中间通信层,所以我采用了相同的设置。好消息是编写了 Node Redis 模块,一旦你安装了所有东西,就很容易测试来回推送消息。

回答by Shripad Krishna

If you are looking at creating real-time apps then go with node.js(high concurrency) alone. You really cannot integrate node.js into a rails app. You can however have a node server setup on another port with an api and websockets configured and then have your rails app communicate with that server. It is PITA to do that kind of setup. You rather build the entire web app in node itself. However, if you want anything rails specific that does not use juggernaut then i would suggest http://www.pusherapp.com.

如果您正在考虑创建实时应用程序,请node.js单独使用(高并发)。您真的无法将 node.js 集成到 Rails 应用程序中。但是,您可以在另一个端口上设置节点服务器,并配置 api 和 websockets,然后让您的 rails 应用程序与该服务器进行通信。做那种设置是PITA。您宁愿在节点本身中构建整个 Web 应用程序。但是,如果您想要任何不使用 juggernaut 的特定 rails,那么我会建议http://www.pusherapp.com

Its extremely easy to setup server push using Pusher.

使用 Pusher 设置服务器推送非常容易。

回答by ptdorf

It already did. Not really NodeJs but a framework built on top if it. Yada, yada, yada... check this out: https://github.com/1602/express-on-railway

它已经做到了。不是真正的 NodeJ,而是一个建立在它之上的框架。雅达,雅达,雅达……看看这个:https: //github.com/1602/express-on-railway

回答by Philip Mutua

**Run node along side your rails server**

**在 Rails 服务器旁边运行节点**

If you want to intergrate your Rails app with Node you could use the node-rails gem

如果你想将你的 Rails 应用程序与 Node 集成,你可以使用node-rails gem

Node Rails will enable you to run a Node server along side your Rails application and have the two share authentication NodeRails assumes you are using Devise for your authentication. Node-Rails uses [redis gem][2] , so you will need to have that installed. Learn more about using npm packages on Rails.

Node Rails 将使您能够在 Rails 应用程序旁边运行一个 Node 服务器,并且假设您使用 Devise 进行身份验证,NodeRails 可以共享两个身份验证。Node-Rails 使用 [redis gem][2] ,所以你需要安装它。 了解有关在 Rails 上使用 npm 包的更多信息。