Closed MattErtel closed 11 years ago
Please refer to the ff. codes below, I hope that helps. I wrote it using haml and coffeescript, I don't like to mix my js codes on the views so I separated them. I didn't create a partial with _create.js.erb that is stated in the railscast video.
in my index.html.erb I have the ff. codes:
%ul#chat
= subscribe_to "/messages/new"
Inside my MessagesController on my create method I have this: def create @message = Message.create!(params[:message])
respond_to do |format|
format.json {
PrivatePub.publish_to("/messages/new", @message)
render :json => { :data => @message }
}
end end
And in my JavaScript code I did something like this: $('#new_message').on 'ajax:success', (e, data) -> this.reset()
PrivatePub.subscribe "/messages/new", (data, channel) -> $('#chat').append "
I used rails js (aka jquery ujs) for resetting and submitting the form.
And run your server and of course the private_pub.ru. And you're good to go.
Thanks for the help. I actually got this working a while back and forgot to close it. I appreciate you taking a look and trying to help. Will close the issue now.
I am having some issues with getting my subscribed clients to update when a new messages is posted. I followed the railscast on this to setup everything, but whenever I publish a message it does not update on any of my clients. I added the debug logging to my private_pub.ru and can confirm the messages make it to the server:
2013-02-19 12:39:00 [INFO] [Faye::Server] Processing messages: [{"channel":"/messages/new","data":{"channel":"/messages/new","data":"message"},"ext":{"private_pub_token":"secret"}}](local: false) 2013-02-19 12:39:00 [DEBUG] [Faye::Engine::Proxy] Publishing message {"channel":"/messages/new","data":{"channel":"/messages/new","data":"message"},"ext":{"private_pub_token":null}} 2013-02-19 12:39:00 [DEBUG] [Faye::Server] Processing reply: {"channel":"/messages/new","successful":true}
My subscribe to function does not ever seem to fire though(index.html.erb): <%= subscribe_to "/messages/new" %>
I know I should be using my message variable in the append but I was just testing and the "Test Index Message" string never appears.
Can anyone help me out with this issue?