How can I use Private Pub with a Resource Route that has a segment key?

自作多情 提交于 2020-01-05 08:16:28

问题


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)


回答1:


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



来源:https://stackoverflow.com/questions/17201127/how-can-i-use-private-pub-with-a-resource-route-that-has-a-segment-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!