I am using faye rails but I believe that the same problem will be with private pub. Following the railscast the users can send messages to each other but I want to mark the messages as read when the recepient receives it. I added some ruby code on the partial because I thought that when the message is evaluated on the recipient wil be executed too. But it not working..
application.js:
$(function() {
var faye = new Faye.Client('http://xxxip/faye');
faye.subscribe('/messages/<%= @conversation.faye_token%>', function (data) {
eval(data);
});
});
create.js.erb:
<% broadcast "/messages/#{@conversation.faye_token}" do %>
$("#chat").append("<%= j(render('message', :message=> @message)) %>");
<% end %>
$('#message_body').val('');
and the partial I am rendering:
<%= message.body %> at <%= message.created_at.strftime("%H:%M, %d %b") %>
I am using faye rails but I believe that the same problem will be with private pub. Following the railscast the users can send messages to each other but I want to mark the messages as read when the recepient receives it. I added some ruby code on the partial because I thought that when the message is evaluated on the recipient wil be executed too. But it not working..
application.js:
$(function() { var faye = new Faye.Client('http://xxxip/faye'); faye.subscribe('/messages/<%= @conversation.faye_token%>', function (data) { eval(data); }); });
create.js.erb:
<% broadcast "/messages/#{@conversation.faye_token}" do %> $("#chat").append("<%= j(render('message', :message=> @message)) %>"); <% end %> $('#message_body').val('');
and the partial I am rendering:
But the ruby code is executed on the recepient only if I reload the whole page.