我正在使用基于 faye /ruby/how-to-use-faye-as-a-real-time-push-server-in-rails/" rel="nofollow noreferrer">本教程 创建聊天消息系统。唯一的问题是,我想要不同的频道“聊天室”,用户可以通过访问他们的网址来订阅。另外,我想用模型来表示每个通道,以便我可以通过名称或索引找到它们。我该怎么做?由于某种原因,我找不到这方面的任何好的资源。顺便说一句,我对 Rails 并不是很陌生,我只是根本不知道如何使用 Faye。
这是我的用例,只是为了清楚起见:
用户访问我的网站。
用户在表单中输入“chat1”,可以说访问
聊天室控制器,索引操作
控制器查找名为“chat1”的所有聊天室
如果找不到,它会实例化一个名为“chat1”的新聊天室并向用户订阅该聊天室
将用户重定向到该聊天室。
I'm using faye based on this tutorial to create a chat message system. The only thing is, I want different channels "chatrooms" that users can subscribe to by visiting their url. Also, I want to represent each channel with a model, so that I can find them by name or index. How do I do this? For some reason, I can't find any good resources on this. By the way, I'm not terribly new to Rails, I just don't know how to use Faye at all.
Here's my use case, just to be clear:
User visits my site.
User enters "chat1" into a form, which lets say accesses
the Chatrooms controller, index action
Controller finds all Chatrooms by name "chat1"
If it can't find it, it instantiates a new chatroom called "chat1" and subscribes the user to it
Redirects user to that chatroom.
发布评论
评论(1)
当您要求订阅时,Faye 似乎会自动创建新频道。例如,在您的 javascript 中,不要订阅“foo”,而是执行以下操作:
Faye seems to automatically create new channels when you ask to subscribe to them. In your javascript, instead of subscribing to "foo" for example, do this: