Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using firebase for chat in one of my rails view and I'm not properly able to capture the value of user input to display on the page. This happened when I added the jquery plugin pageslide. I must have missed something in my implementation for these two to be working together.

Here the show page for my rails view-

<script src="https://cdn.firebase.com/v0/firebase.js"></script>

<div id='chat-window'> 
  <%= render 'chat_window' %>
</div>
<a href="#chatty" class="second">Open Chat</a>

Here is the chat_window partial-

<% if @list.chat_enabled %>
  <%= render 'chat' %>
<% else %>
  <% if @list.owner?(current_user) %>
    <%= link_to 'Get ' + @list.name + "Chat Ticket",  enable_chat_list_path(@list), :class => 'btn', :remote => true %>
  <% end %>
<% end %>

here is the chat partial-

<div id="chatty" >
  <ol id='messagesDiv' class="conversation">  
  </ol>
  <input id='messageInput' class="conversation" placeholder='Message...'>
  <a href="javascript:$.pageslide.close()"><span class="btn btn-info">Done Chatting</span></a>
</div>

<script>
  $(document).ready(function() {
      $(".second").pageslide({ direction: "left", modal: true });
  });
</script>

Here is the coffeescript file for enabling and writing the chat based on firebase documentation-

window.enableChat = (baseRef, projRef, userName, token) ->
  # Get a reference to the root of the chat data.
  messagesRef = new Firebase(baseRef)
  projectRef = ''
  messagesRef.auth token, (error, user) ->
    if error
      $("#messageInput").prop('disabled', true)
      $("#messagesDiv").html('disabled')
    else
      projectRef = messagesRef.child(projRef)

      # Add a callback that is triggered for each chat message.
      projectRef.on "child_added", (snapshot) ->
        message = snapshot.val()
        $("<li class='self'>").append($("<div class='message'>").append($("<p>").text(message.text))).prepend($("<span class='userVal'/>").text(message.name + ": ")).appendTo $("#messagesDiv")

      # When the user presses enter on the message input, write the message to firebase.
      $("#messageInput").keypress (e) ->
        if e.keyCode is 13
          text = $("#messageInput").val()
          projectRef.push 
            name: userName
            text: text
          $("#messageInput").val ""

More info If I use the chat without activating the pageslide the chat writes to the show page just fine. enter image description here

Once I activate the pageslide and use the text box a new li will be appended to the list on the main show page but will not have any value in it. And nothing with append to the list inside of the pageslide.

enter image description here

This link <a href="#chatty" class="second123">Open Chat</a> is used to open the jQuery pageslide plugin.

Nothing from the console when hitting enter inside the jQuery pageslide plugin.

How can I better troubleshoot this problem?

share|improve this question
I believe I understand the issue better. Pageslide plugin created a <div id="pageslide"></div> and I had my chat data wrapped inside of it. I remedied this issue by adding #pageslide before the references in the coffee file. So $('#messagesDiv') becomes $('div#pageslide #messagesDiv') – Tmacram yesterday

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.