ruby-on-rails-3.2coffeescriptprivate-pub

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


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)


Solution

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