不显示faye消息

时间:2015-07-19 13:07:59

标签: ruby-on-rails thin faye

我使用此页面制作了一个简单的faye教程:

http://code.tutsplus.com/tutorials/how-to-use-faye-as-a-real-time-push-server-in-rails--net-22600

并且显示了消息显示的常见问题 - 服务器获取参数并呈现它,但页面上没有任何反应。我有alredy修复faye.ru文件,正如在评论中推荐的那样。我该怎么办?

大部分代码都存储在视图中:

<script>
  $(function() {
    // Subscribe to receive messages!
    var client = new Faye.Client('http://localhost:9292/faye');

    // Our public subscription
    var public_subscription = client.subscribe('/messages/public',    function(data) {
  $('<p></p>').html(data.username + ": " + data.msg).appendTo('#chat_room');
});

// Our own private channel
var private_subscription = client.subscribe('/messages/private/<%= session[:username] %>', function(data) {
  $('<p></p>').addClass('private').html(data.username + ": " + data.msg).appendTo('#chat_room');
});

// Handle form submission to publish messages.
$('#new_message_form').submit(function(){
  // Is it a private message?
  if (matches = $('#message').val().match(/@(.+) (.+)/)) {
    client.publish('/messages/private/' + matches[1], {
      username: '<%= session[:username] %>',
      msg: matches[2]
    });
  }
  else {
    // It's a public message
    client.publish('/messages/public', {
      username: '<%= session[:username] %>',
      msg: $('#message').val()
    });
  }

  // Clear the message box
  $('#message').val('');

  return false;
});
  });

   <div class="chat_container">
     <div id="chat_room">
       <p class="alert"> Welcome to the chat room <%= session[:username] %>!       </p>
 </div>

 <form id="new_message_form">
   <input type="text" id="message" name="message">
   <input type="submit" value="Send">
 </form>
</div>

1 个答案:

答案 0 :(得分:0)

好吧,我用“rails server thin”取代了“rails s thin”,并且通过某种魔术,它已经开始工作了