简体   繁体   English

Ruby on rails和Node.js

[英]Ruby on rails and Node.js

I am wondering how to integrate node.js on a rails app (for learning purpose). 我想知道如何在rails应用程序上集成node.js(用于学习目的)。

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. 基于Michael Hartl教程( http://railstutorial.org/ ),我实现了一个带有rails的基本twitter克隆,并希望在不使用彗星或剑圣的情况下实时获取用户微博。 (the application is hosted on heroku) (该应用程序托管在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. 目前,我只看到了node.js框架的示例( http://howtonode.org/grasshopper-shoutbox ),但没有与rails应用程序上的ruby合并。 I would be very thankful if someone knows a good tutorial or give me some points to start in order to accomplish this. 如果有人知道一个好的教程或者为了完成这个目的而给我一些要点,我将非常感激。

Thanks! 谢谢!

As Shripad said, I'd consider trying to build your app with Node by itself. 正如Shripad所说,我会考虑尝试用Node自己构建你的应用程序。 Geddy will feel familiar (getting started anyway) if you have experience with Rails. 如果你有使用Rails的经验, Geddy会觉得熟悉(无论如何都是入门)。 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. 注意:我没有使用Geddy的真实世界应用程序的经验,但它是迄今为止我见过的最好的Rails框架。 For persistence you can use SQLite, PostgreSQL or CouchDB, just like you would with Rails. 对于持久性,您可以使用SQLite,PostgreSQL或CouchDB,就像使用Rails一样。 I thought about how to communicate between a Rails app and Node without any intermediary. 我想过如何在没有任何中介的情况下在Rails应用程序和Node之间进行通信。 In our work project we're using Redis as an intermediary between Rails and Node. 在我们的工作项目中,我们使用Redis作为Rails和Node之间的中介。 Rails publishes messages to Redis, Node pulls messages from Redis. Rails向Redis发布消息,Node从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. 好消息是编写Node Redis模块,一旦安装好所有内容,就可以轻松测试来回推送消息。

If you are looking at creating real-time apps then go with node.js (high concurrency) alone. 如果您正在考虑创建实时应用程序,那么单独使用node.js (高并发)。 You really cannot integrate node.js into a rails app. 你真的无法将node.js集成到rails应用程序中。 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. 但是,您可以在另一个端口上安装节点服务器,并配置api和websockets,然后让rails应用程序与该服务器通信。 It is PITA to do that kind of setup. 是PITA做那种设置。 You rather build the entire web app in node itself. 您宁愿在节点本身中构建整个Web应用程序。 However, if you want anything rails specific that does not use juggernaut then i would suggest http://www.pusherapp.com . 但是,如果你想要任何不使用juggernaut的特定轨道,那么我会建议http://www.pusherapp.com

Its extremely easy to setup server push using Pusher. 使用Pusher极易设置服务器推送。

It already did. 它已经做到了。 Not really NodeJs but a framework built on top if it. 不是NodeJs,而是建立在顶层的框架。 Yada, yada, yada... check this out: https://github.com/1602/express-on-railway Yada,yada,yada ......看看这个: https//github.com/1602/express-on-railway

**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. 节点Rails将使您能够在Rails应用程序旁边运行节点服务器并拥有两个共享身份验证NodeRails假定您使用Devise进行身份验证。 Node-Rails uses [redis gem][2] , so you will need to have that installed. Node-Rails使用[redis gem] [2],因此您需要安装它。 Learn more about using npm packages on Rails. 了解有关在Rails上使用npm包的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM