ryanb / private_pub

Handle pub/sub messaging through private channels in Rails using Faye.
MIT License
864 stars 228 forks source link

erb code not execute on partial after broadcasting #108

Open matzavinosg opened 9 years ago

matzavinosg commented 9 years ago

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") %>

<%if message.recipient_id.to_s == session[:user_id].to_s%>
<%message.reading%>
<%end%>

But the ruby code is executed on the recepient only if I reload the whole page.