如何使用具有段密钥的资源路由的私有Pub? [英] How can I use Private Pub with a Resource Route that has a segment key?

查看:158
本文介绍了如何使用具有段密钥的资源路由的私有Pub?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails 3项目中使用私人网址时遇到问题。
所有示例显示了发布/订阅路由的用法,如下所示:
/ messages / new
但是如果预期路由有点更复杂,即。



routes.rb

  resources:messages,only:[] do 
post'chat',on::member
end

这将创建以下

  chat_message POST / messages /:id / chat :format)message#chat 

因此,我使用它像这样:



查看:



= subscribe_to/ messages /#{@ cid} / chat p>

咖啡响应视图

  %publish_to/messages/#{current_user.convos.first.id}/chatdo%> 
$('#message-display')。append(<%= j render partial:'shared / single_message',locals:{user:current_user}%>)
& end%>

但是块不会被触发!它应该是同一条路线,对吧?我的意思是,段键匹配...
它不会在任何视图中工作,块内的代码永远不会达到。我做错了什么?



请帮助我!



Jose。



注意。我看过的所有例子似乎都展示了这个gem用于一般聊天的使用。我的目的是为各种对等私人对话创建各种渠道(像Facebook聊天)

解决方案

CoffeeScript不处理红宝石块。他们是红宝石块。而且你不能链接在views /文件夹中的扩展。


I'm currently having a problem while using Private Pub in a Rails 3 Project. All the examples show the usage of publish/subscribe to a route like this: "/messages/new" But What If the intended route is a little more complex, ie.

routes.rb

resources :messages, only: [] do
  post 'chat', on: :member  
end

Which will create the following

chat_message POST /messages/:id/chat(.:format) messages#chat

Therefore, I'm using it like this:

view:

= subscribe_to "/messages/#{@cid}/chat"

coffee response view:

<% publish_to "/messages/#{current_user.convos.first.id}/chat" do %>
$('#message-display').append("<%= j render partial: 'shared/single_message', locals: { user: current_user } %>")
<% end %>

But the block will never get triggered! It's supposed to be the same route, right? I mean, the segment key matches... It won't work in any views at all, the code inside the block is never reached. What am I doing wrong?

Please help me!

Jose.

Note. All the examples I've seen seem to showcase the use of this gem for a general chat. My intention, is to create various channels, for various peer-to-peer private conversations (Like Facebook chat)

解决方案

CoffeeScript doesn't handle ruby blocks. They're ruby blocks. And you can't chain extension in the views/ folder.

这篇关于如何使用具有段密钥的资源路由的私有Pub?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆